Text To Speech PDF
Text To Speech PDF
Text-to-speech and
Speech-to-text
This document is copyright (C) Marty Stepp and Stanford Computer Science.
Licensed under Creative Commons Attribution 2.5 License. All rights reserved.
Text-to-Speech
● text-to-speech: Allows Android device to speak an audible
message based on a text string.
– Not installed by default on some devices. To install, click
Settings → Language and Input → Text to speech output → Google text-
to-speech engine "settings" icon → Install voice data → Languages
@Override
protected void onActivityResult(int requestCode,
int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
ArrayList<String> list = intent.getStringArrayListExtra(
RecognizerIntent.EXTRA_RESULTS);
String spokenText = list.get(0);
// ...
}
Robust speech-to-text code
● Some devices do not have speech-to-text capability.
– In these cases, it will throw an exception when you try to use it.
– To handle such situations, you can try/catch the exception.