Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I control how Android TTS plays audio

I have a class that uses the Android TTS API to transcribe text to audio. I can control the pitch and speed; but I noticed the engine requires a text string and also a hash object. I noticed some words are pronounced too quickly to be easily recognized, and inflection seems too unnatural. Is there a way I can control these two things; possibly through the HashMap? The following is how I'm using the engine:

    mTts = new TextToSpeech(Globals.context, this); // context, listener
}

@Override
public void onInit(int status) {
    HashMap<String, String> myHashRender = new HashMap();
    myHashRender.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, speech);
    mTts.setPitch(0.8f);
    mTts.setSpeechRate(0.6f);
    mTts.synthesizeToFile(speech, myHashRender, fileOutPath);
    while (mTts.isSpeaking()) try {
        Thread.sleep(100);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    mTts.stop();
    mTts.shutdown();
like image 272
motoku Avatar asked Feb 07 '15 19:02

motoku


People also ask

How do I slow down text-to-speech on Android?

Tap the Settings icon . Scroll down and tap Accessibility. Scroll down and tap Text-to-speech output. Adjust the sliders for Speech Rate and Pitch.

What is TTS setting?

Created May 2019. Text-to-speech (TTS) is the underlying software used by screen readers, such as TalkBack and Select to Speak, when they convert text into spoken content. You can customise the text-to-speech voice to make it easier to follow.

What is AddSpeech () method in Android?

AddSpeech(String, String) Adds a mapping between a string of text and a sound file.


1 Answers

Google TTS does not currently support that, but here is what you can do: During parsing of your text, you can change parts of it to get the intonation and inflection you want.

For example, if you encounter the word 'Hey' you rewrite it on the fly to 'Heeeey' before you send it to the TTS engine to get a different pronounciation.

It is not pretty but it is a workaround.

like image 103
DKIT Avatar answered Sep 20 '22 13:09

DKIT