Android TTS fails to speak large amount of text

后端 未结 5 1394
没有蜡笔的小新
没有蜡笔的小新 2021-01-02 05:01

I am trying to speak out large amount of text using Android Text To Speech. I using default Google speech engine. Below is my code.

 public class Talk extend         


        
5条回答
  •  滥情空心
    2021-01-02 05:28

    Use this code...Working for any file .. just send the string to speech function..

    private void speech(String charSequence) {
    
        int position ;
    
    
        int sizeOfChar= charSequence.length();
        String testStri= charSequence.substring(position,sizeOfChar);
    
    
        int next = 20;
        int pos =0;
        while(true) {
            String temp="";
            Log.e("in loop", "" + pos);
    
            try {
    
          temp = testStri.substring(pos, next);
                HashMap params = new HashMap();
                params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, temp);
                engine.speak(temp, TextToSpeech.QUEUE_ADD, params);
    
                pos = pos + 20;
                next = next + 20;
    
            } catch (Exception e) {
                temp = testStri.substring(pos, testStri.length());
                engine.speak(temp, TextToSpeech.QUEUE_ADD, null);
                break;
    
            }
    
        }
    
    }
    

提交回复
热议问题