Code example for TextToSpeech

0
    public void initTTS() { 
        // Initialize text-to-speech. This is an asynchronous operation. 
        // The OnInitListener (second argument) is called after initialization completes. 
        Log.i(TAG, "Initializing TextToSpeech...");
        mTts = new TextToSpeech(mService,
            this  // TextToSpeech.OnInitListener
            ); 
    } 
    public void shutdownTTS() { 
        Log.i(TAG, "Shutting Down TextToSpeech...");
 
        mSpeakingEngineAvailable = false;
        mTts.shutdown();
        Log.i(TAG, "TextToSpeech Shut Down.");
 
    } 
    public void say(String text) {
        if (mSpeak && mSpeakingEngineAvailable) {
            mTts.speak(text,
                    TextToSpeech.QUEUE_ADD,  // Drop all pending entries in the playback queue.
Experience pair programming with AI  Get Codota for Java