【问题标题】:text to speech not working as initialization is not over文本到语音无法正常工作,因为初始化尚未结束
【发布时间】:2017-03-23 06:05:21
【问题描述】:

我正在关注这个问题以使 tts 工作

Android TTS doesn't speak

但在他给出的答案中说(gameover,true),say(line,false),say(definition_string,false)

请任何人帮助我,告诉我这些术语是什么。

这是我的代码

public class SecondActivity extends AppCompatActivity implements OnInitListener {
    TextToSpeech t1;
   // private final int REQ_CODE_SPEECH_INPUT = 100;
    String emailid;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        emailid="Hi,say your email id";

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
        t1=new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(int status) {
                if(status != TextToSpeech.ERROR) {
                    t1.setLanguage(Locale.US);

                }
            }
        });

        Toast.makeText(getApplicationContext(), emailid,Toast.LENGTH_SHORT).show();
        t1.speak(emailid, TextToSpeech.QUEUE_FLUSH, null);



    }

    public void onPause(){
        if(t1 !=null){
            t1.stop();
            t1.shutdown();
        }
        super.onPause();
    }
  }

【问题讨论】:

  • 您的问题究竟是什么?如果您在理解您发布的主题时有任何困难,请在该帖子中解决或详细说明您的问题。
  • @Ispas Claudiu 我已经编辑了问题。请检查

标签: android speech-recognition text-to-speech voice-recognition google-text-to-speech


【解决方案1】:

试试这个,看看它是否有效:

public class TextToSpeechController implements TextToSpeech.OnInitListener{

private Context mContext;

private TextToSpeech tts;

public TextToSpeechController(Context context) {
    mContext = context;
    tts = new TextToSpeech(context, this);
}

@Override
public void onInit(int status) {
    Log.e("INIT TTS", "INIT");
    if (status == TextToSpeech.SUCCESS) {
            int result = tts.setLanguage(Locale.ENGLISH);

            if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
                   Toast.makeText(mContext, "This Language is not supported", Toast.LENGTH_LONG).show();
            }
            else {
                Toast.makeText(mContext, "Ready to Speak", Toast.LENGTH_LONG).show();
                speakTheText("Welcome to the App");
            }

    } 
    else {
         Toast.makeText(mContext, "Can Not Speak", Toast.LENGTH_LONG).show();
    }   
}

public void stopTTS(){
    tts.stop();
    tts.shutdown();
}

 public void speakTheText(String str){
     tts.speak(str, TextToSpeech.QUEUE_FLUSH, null);
 }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-05
    • 1970-01-01
    • 2018-12-31
    相关资源
    最近更新 更多