文本到语音不会读取设定的语言

时间:2018-06-04 15:55:07

标签: java android text-to-speech google-text-to-speech

我正在制作法语学习应用程序,但有时初始化使用的速度非常慢。我已经多次讨论过这个问题,我找到了这些解决方案; Android: two instances of Text-to-Speech work very slowlyText To Speech app UI is slow androidInitialising the TextToSpeech object on a worker threadhttps://blog.fossasia.org/implementing-text-to-speech-tts-in-susi-android/。我尝试了以下代码。

    private volatile TextToSpeech engine;
    private TextToSpeech.OnInitListener volatileOnInitListener;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_word_card);

    //setting
    mSetting = getSharedPreferences("setting", Context.MODE_PRIVATE);
    mIsAutoPlay = mSetting.getBoolean("autoPlay", false);


    AsyncTask.execute(new Runnable() {
        @Override
        public void run() {
            engine = new TextToSpeech(WordCardActivity.this, volatileOnInitListener);
        }
    });

    @Override
    public void onInit(int status) {
    Log.d("Speech", "OnInit - Status [" + status + "]");

    if (status == TextToSpeech.SUCCESS) {
        Log.d("Speech", "Success!");
        engine.setLanguage(Locale.FRENCH);
        if(mIsAutoPlay){
            speech();
        }
    }
}

private void speech() {
    engine.speak(mWord, TextToSpeech.QUEUE_FLUSH, null, null);
}

    }

结果,初始化变得更快,但TextToSpeech读取单词的字母而不是单词本身。例如,“S'il vous plait”被读作“S,I,L,V,O,U,S,P,L,A,I,T”。由于我的Android手机是日本手机,它的发音是日本式的。我不知道为什么会这样,但似乎语言没有设置法语(这只是我的猜测)。 有人可以帮忙吗?提前致谢。

0 个答案:

没有答案