在Android活动中实施文字转语音时不会出现声音

时间:2016-09-12 19:34:51

标签: android text-to-speech

我在我的一款应用中使用TextToSpeak。将语音字符串添加到TextToSpeech对象实例时,它不会产生任何声音。虽然我没有在日志中收到任何错误,但仍然没有出现声音。我希望设备发言,因为textview的值由resultMSG.setText()方法设置。

public class ResultActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState){
        ............
        resultMSG.setText(resultMSG_STR);
        textToSpeech = new TextToSpeech(getApplicationContext(),newTextToSpeech.OnInitListener(){

            @Override
            public void onInit(int status) {
                System.out.println("Txt To Speech STATUS = "+status);
                System.out.println("Txt To Speech Error STATUS = "+TextToSpeech.ERROR);
                System.out.println("Txt To Speech Success STATUS = "+TextToSpeech.SUCCESS);
                if(status == TextToSpeech.SUCCESS){
                    textToSpeech.setLanguage(Locale.ENGLISH);
                }
            }
        });
textToSpeechResult = textToSpeech.speak(resultMSG_STR,TextToSpeech.QUEUE_ADD,null);
    }
}

1 个答案:

答案 0 :(得分:0)

检查音量是否足够响亮。您可能还想从Play商店安装应用程序,以验证TTS是否可以在您的手机上运行。

您可能还想将代码移出onCreate方法并进入onResume方法。

查看我自己的代码,我注意到我有#34;说"在init回调中调用。我在想你的"说"在您的TTS完全初始化之前调用call。