安卓:说话失败:不绑定到TTS引擎 [英] Android : speak failed : not bound to tts engine

查看:6837
本文介绍了安卓:说话失败:不绑定到TTS引擎的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的应用程序即能说话。

I have a simple app that is able to speak.

的东西是我在logcat中得到这个错误:

The things is I got this error in logcat:

TextToSpeech Sucessfully bound to com.ivona.tts
TextToSpeech speak failed : not bound to TTS engine

我加什么特别的Andr​​oid清单,确实有?

I add nothing particular in the Android manifest, do have to ?

code

import java.util.Locale;

import android.app.Activity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
import android.util.Log;

public class Main extends Activity implements OnInitListener{

TextToSpeech tts;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    tts = new TextToSpeech(this, this);

    tts.speak("Hello World", TextToSpeech.QUEUE_FLUSH, null);       
}

@Override
protected void onDestroy() {
    MyTTS.release();
    super.onDestroy();
}

@Override
public void onInit(int status) {
    if (status == TextToSpeech.SUCCESS) {
        tts.setLanguage(Locale.getDefault());
    } else {
        Log.e("TTS", "Initialization failed");
    }

}

}

我不知道为什么这个错误发生时。
谁能帮我?
预先感谢

I don't know why this error occurs. Can anyone help me? Thank in advance

编辑:我不想把speak方法里面的OnInit方法。我该怎么办呢?

Edit : I don't want put the speak method Inside the onInit method. How can I do it ?

推荐答案

您只能让发动机说话,OnInit的完成后,所以做你的OnInit()如下:

You can only let the engine speak, after onInit is done, so do following in You onInit():

   if (status == TextToSpeech.SUCCESS) {
     tts.speak("Hello World", TextToSpeech.QUEUE_FLUSH, null);      

   }

这篇关于安卓:说话失败:不绑定到TTS引擎的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆