【问题标题】:speak failed:not bound to tts engine说话失败:未绑定到 tts 引擎
【发布时间】:2016-05-18 02:58:01
【问题描述】:

问题:说话失败:未绑定到tts engine

我正在实现textToSpeech 功能。我收到了发言失败的异常:未绑定到tts engine。我正在用它实现async taskasync task 将读取 mail。我想转换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);
}


}

【问题讨论】:

  • 你能发布堆栈跟踪吗?

标签: java android eclipse email text-to-speech


【解决方案1】:

您的 google 文本转语音引擎可能已被禁用...一旦在您的设置上检查它

如果禁用它也会显示相同的错误

【讨论】:

    【解决方案2】:

    您应该将 tts 引擎实例的实例化移动到 onCreate,这一行:

    public TextToSpeech tts = new TextToSpeech(MainActivity.c, Notify.this);
    

    改为:

    public TextToSpeech tts;
    

    并在您的onCreate 中添加:

        tts = new TextToSpeech(MainActivity.c, Notify.this);
    

    而且 - 最重要的是 - 不要在 Activity 派生类中使用构造函数:

     public Notify()
     {
         System.out.println("Inside Constructor");
         speakOut();
     }
    

    应该是你的 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);
     }
    

    【讨论】:

      猜你喜欢
      • 2014-02-25
      • 2012-07-31
      • 1970-01-01
      • 1970-01-01
      • 2023-03-06
      • 2021-01-24
      • 2016-05-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多