Reputation: 47
Issue : speak failed:not bound to tts engine
I am implementing textToSpeech
functionality. I am getting the exception as speak failed: not bound to tts engine
. I am implementing the async task
with it. the async task
will be reading the mail
. And i want to convert the mail body to speech
.
package com.example.trynot;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import java.util.Locale;
import com.example.trynot.MainActivity.ReadMailSample;
import android.app.Activity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class Notify extends Activity implements TextToSpeech.OnInitListener {
/** Called when the activity is first created. */
public TextToSpeech tts = new TextToSpeech(MainActivity.c, Notify.this);
public Notify()
{
System.out.println("Inside Constructor");
speakOut();
}
@Override
public void onDestroy() {
// Don't forget to shutdown tts!
if (tts != null) {
tts.stop();
tts.shutdown();
}
super.onDestroy();
}
@Override
public void onInit(int status) {
System.out.println("inside INIT");
if (status == TextToSpeech.SUCCESS) {
int result = tts.setLanguage(Locale.US);
tts.speak(MainActivity.ReadMailSample.command, TextToSpeech.QUEUE_FLUSH, null);
if (result == TextToSpeech.LANG_MISSING_DATA
|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.e("TTS", "This Language is not supported");
} else {
speakOut();
}
} else {
Log.e("TTS", "Initilization Failed!");
}
}
private void speakOut() {
System.out.println("inside SPeak out");
tts.speak(MainActivity.ReadMailSample.command, TextToSpeech.QUEUE_FLUSH, null);
}
}
Upvotes: 0
Views: 2242
Reputation: 1030
your google text to speech engine may be disable... once check it on your setting
if it is disable it also shows the same error
Upvotes: 1
Reputation: 49986
You should move instatiation of tts engine instance to onCreate, this line:
public TextToSpeech tts = new TextToSpeech(MainActivity.c, Notify.this);
change to:
public TextToSpeech tts;
and add inside your onCreate
:
tts = new TextToSpeech(MainActivity.c, Notify.this);
And - whats most important - do not use constructor in Activity derived classes:
public Notify()
{
System.out.println("Inside Constructor");
speakOut();
}
should be your onCreate:
@Override
protected void onCreate (Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//speakOut(); // here tts is not yet initialized, call it in onInit on success
//tts = new TextToSpeech(MainActivity.c, Notify.this); // whats MainActivity.c?
tts = new TextToSpeech(this, this);
}
Upvotes: 1