Controlling input for Google TTS API

I'm creating a TTS app using google's unofficial tts api and it works fine but the api can only process a maximum of 100 characters at a time but my application may have to send strings containing as many as 300 characters.

Here is my code

        try {
        String text = "bonjour comment allez-vous faire";

        text=text.replace(" ", "%20"); 
        String oLanguage="fr";

        MediaPlayer player = new MediaPlayer();
        player.setAudioStreamType(AudioManager.STREAM_MUSIC);           
        player.setDataSource("http://translate.google.com/translate_tts?tl=" + oLanguage + "&q=" + text);

        player.prepare();
        player.start(); 

    } catch (Exception e) { 
        // TODO: handle exception
    }

So my questions are

  1. How do I get it to check the number of characters in the string and send only complete words within the 100 character limit.

  2. How do I detect when the first group of TTS is finished so I can send the second to avoid both speech overlapping each other

  3. Is there any need for me to use Asynctask for this process?

Answers


1.How do I get it to check the number of characters in the string and send only complete words within the 100 character limit.

    ArrayList<String> arr = new ArrayList<String>();
    int counter = 0;
    String textToSpeach = "Your long text";
    if(textToSpeach.length()>100)
    {   
        for(int i =0 ; i<(textToSpeach.length()/100)+1;i++)
        {
        String temp = textToSpeach.substring(0+counter,99+counter);
        arr.add(temp.substring(0, temp.lastIndexOf(" ")));
        counter = counter + 100;
        }
    }

2.How do I detect when the first group of TTS is finished so I can send the second to avoid both speech overlapping each other

    player.setOnCompletionListener(new OnCompletionListener() {

        @Override
        public void onCompletion(MediaPlayer mp) {

            // pass next block
        }
    });

3.Is there any need for me to use Asynctask for this process?

Right now I dont see any need for that.


Simple: this is not a public API, don't use it. Use Andorid's built-in TTS engine for speech synthesis. It does not have string length limitations.


Need Your Help

How to share client side internet connection with server side in openvpn?

connection reverse sharing openvpn

I setup an openvpn server on Ubuntu 14.04 in Japan and my brother setups an openvpn client on Ubuntu 14.04 In Switzerland. The vpn connection successfully work and ping requests form client side or

Button Thread-Safe Calls to Windows Forms Controls C#

c# multithreading winforms button windows-forms-designer

I had read this topic about how to Make Thread-Safe Calls to Windows Forms Controls .. But I don't really understand how to apply it to a button. In my case I have: