Android TTS fails to speak large amount of text

后端 未结 5 1401
没有蜡笔的小新
没有蜡笔的小新 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:24

    The String length should not be longer than pre-defined length, from docs:

    Parameters

    text The string of text to be spoken. No longer than getMaxSpeechInputLength() characters.

    Returned value by getMaxSpeechInputLength() may vary from device to device, but according to AOSP source that is whopping 4000:

    /**
     * Limit of length of input string passed to speak and synthesizeToFile.
     *
     * @see #speak
     * @see #synthesizeToFile
     */
    public static int getMaxSpeechInputLength() {
        return 4000;
    }
    

    Try not to exceed that limit: compare input text length with that value and split into separate parts if necessary.

提交回复
热议问题