title: Is there a pattern to when Android TTS network voice falls back to local?
body: <p>I'm trying to use the Android Text-to-Speech feature (engine: com.google.android.tts) in my app to read a long document to a wav file. That basic functionality works very well and it technically does what I'm asking. I want to use one of the voices that requires network connection because they sound a lot clearer.</p>
  <p>Again, this works. But it only works reliably with short text. I can write a few sentences to a file and it works just fine. But if I increase the length of the text - say, 200 lines of text - there seems to be only a 50/50 (or even less) chance the voice used in the file will actually be the one I requested. The other times the voice that is used is clearly the local/non-network version of that voice. My conclusion is that at some point the text gets too long for the network voice to process and it downgrades to the local voice. BUT not always. Sometimes it works. I've not been able to discern a pattern.</p>
  <p>I've tried many different variations in my code but the vary basic version is this</p>
  <p>TextToSpeech class:</p>
  <pre><code>public class SpeechSynthesizerSimple implements TextToSpeech.OnInitListener {
     TextToSpeech textToSpeech;
  
     public SpeechSynthesizerSimple(Context context) {
         textToSpeech = new TextToSpeech(context, this, &quot;com.google.android.tts&quot;);
     }
  
     @Override
     public void onInit(int status) {
         if (status == TextToSpeech.SUCCESS) {
  
             Set&lt;String&gt; a = new HashSet&lt;&gt;();
             Voice voice = new Voice(&quot;en-us-x-iol-network&quot;, new Locale(&quot;en&quot;, &quot;US&quot;), 400, 200, true, a);
             int voiceSetResult = textToSpeech.setVoice(voice);
  
             if (voiceSetResult == TextToSpeech.LANG_MISSING_DATA || voiceSetResult == TextToSpeech.LANG_NOT_SUPPORTED) {
                 Log.e(&quot;TTS&quot;, &quot;This Language is not supported&quot;);
             } else {
                 Log.e(&quot;TTS&quot;, &quot;Ready&quot;);
             }
  
             textToSpeech.setOnUtteranceProgressListener(
                 new UtteranceProgressListener() {
                    @Override
                    public void onStart(String s) {
                    }
  
                    @Override
                    public void onDone(String s) {
                       Log.e(&quot;TTS&quot;, &quot;Complete&quot;);
                    }
  
                    @Override
                    public void onError(String s) {
                    }
             });
  
         } else {
          Log.e(&quot;TTS&quot;, &quot;Failed!&quot;);
         }
     }
  
     public void SynthesizeToFile(String text, String filePath, String fileName) {
         File file = new File(filePath + &quot;/&quot; + fileName + &quot;.wav&quot;);
         int result  = textToSpeech.synthesizeToFile(text,null, file , &quot;sample_key&quot;);
  
         Log.i(&quot;TTS&quot;,&quot;Result: &quot; + result);
  
     }
  }
  </code></pre>
  <p>and the method that calls it:</p>
  <pre><code> Button synthesizeButton = findViewById(R.id.SynthesizeButton);
   synthesizeButton.setOnClickListener(v -&gt; {
  
          List&lt;String&gt; lines = new ArrayList&lt;&gt;();
          //add some lines of text here
  
          // creates short individual files. Always uses network voice
          for (int i = 0; i &lt; lines.size(); i++) {
              String line = lines.get(i);
              synthesizer.SynthesizeToFile(line, appFolderPath, &quot;some_file_name_&quot; + (i + 1));
          }
  
          // creates one longer file (still less than 4000 chars), 50/50 if the voice will work
          StringBuilder builder = new StringBuilder();
          for (int i = 0; i &lt; lines.size(); i++) {
              String line = lines.get(i);
              builder.append(line);
          }
          synthesizer.SynthesizeToFile(builder.toString(), appFolderPath, &quot;some_file_name&quot;);
  
      });
  </code></pre>
  <p>Does anyone have an idea what the criteria might be for keeping the network voice engaged? Can I alter the way I'm requesting the voice maybe?</p>