Beruflich Dokumente
Kultur Dokumente
Android
Text to Speech
And Speech To Text
Android
TEXT TO SPEECH
Text to Speech
In Android 1.6+ there is a native
Text-to-speech built into the Android
OS.
In 2.3.3, Menu-> Voice input & output->
Text-to-speech settings
In 4.X, Settings-> Language and Input
-> Text-to-speech output
You can use the Listen to an example
to see how it works.
How it works.
The Text-to-Speech (TTS) uses a the
Pico engine
It sends the speech to the audio
output.
Android.speech.tts
To use the TTS we need get access to it using
the constructor
TextToSpeech(Context context,
TextToSpeech.OnInitListener listener)
The constructor for the TextToSpeech class.
OnInitListener
onInit(int status)
Called to signal the completion of the
TextToSpeech engine initialization.
Status is either
TextToSpeech.SUCCESS
You can use it.
or
TextToSpeech.ERROR
Failure, you cant use it.
Example
mTts.speak(Test,
TextToSpeech.QUEUE_ADD, null);
You should hear the word test spoken.
Other methods.
You can change the pitch and speech rate
with
setPitch(float pitch)
setSpeechRate(float speechRate)
Note
In the OnPause() method
You should put at least a stop() call
You app has lost focus
Example code
Txt2spk example in github
Simple text box and button. Type in the
words you want to speak and then press
play.
If you are running the example on a
phone
For fun, use the voice input (microphone on
the keyboard) for the input and then have it
read it back to you.
Android
SPEECH TO TEXT
Speech To Text
Like Text to speech, we are going to call on
another Google's voice recognition software.
Android.speech package
The simple version uses an intent and there is a
dialog box for the users to know when to speech.
RecognizerIntent
With a onActivityResult
SpeechRecognizer class
A second version is more complex, but also
removes the dialog box
Which many people want implement their own or
just not have one.
SpeechRecognizer
First get the recognizer
sr =
SpeechRecognizer.createSpeechRecog
nizer(this);
Set your listener.
sr.setRecognitionListener(new
Recognitionlistener());
Listener is on the next slide.
RecognitionListener
create a Recognitionlistener and implement the following methods
void onBeginningOfSpeech()
The user has started to speak.
void onEndOfSpeech()
Called after the user stops speaking.
RecognitionListener (2)
onResults methods
This is where you would pull out the
results from the bundle
ArrayList results =
results.getStringArrayList(SpeechRecogn
izer.RESULTS_RECOGNITION);
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,getClass().getPa
ckage().getName());
Given an hint to the recognizer about what the user is going to say
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerInte
nt.LANGUAGE_MODEL_FREE_FORM);
Specified the max number of results
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,5);
Use our SpeechRecognizer to send the intent.
sr.startListening(intent);
The listener will now get the results.
Code Examples
The txt2spk will speak text
Speak2Text demo shows you more
information on using other languages
for voice recognition, plus will speak
the results back to you.
speech2txtDemo is simplified voice
recognition
speech2txtDemo2 is uses the
RecognitionListener.
iSpeech
There have SDK and API for blackberry,
android, and iphone as well.
Text to speech
With many voice options as well
Speech to text
Limited to 100 word demo key per application
launch.
License key removes the 100 word limit.
http://www.ispeech.org/
References
http://
developer.android.com/resources/samples/ApiDemos/
src/com/example/android/apis/app/TextToSpeechActi
vity.html
http://
developer.android.com/reference/android/speech/Sp
eechRecognizer.html
http://
developer.android.com/resources/samples/ApiDemos/
src/com/example/android/apis/app/VoiceRecognition
.html
http://
Q&A