Original Author Paul Laughton, 2011
Page 138
De Re BASIC!
Most speech engines limit the number of characters they are able to speak. The limit is not the same for
all devices or all speech engines, but it is typically around 4000 characters. If you exceed the limit, most
engines fail silently: you don't get an error message, but you don't get any speech output, either.
TTS.init
This command must be executed before speaking.
TTS.speak <sexp> {, <wait_lexp>}
Speaks the string expression. The statement does not return until the string has been fully spoken,
unless the optional "wait" parameter is present and evaluates to false (numeric 0). Spoken expressions
cannot overlap. A second TTS.speak (or a TTS.speak.toFile) will wait for the speech from an earlier
TTSts.speak to finish, even if the "wait" flag was false.
TTS.speak.toFile <sexp> {, <path_sexp>}
Converts the string expression to speech and writes it into a wav file. You can specify the name and
location of the file with the optional "path" parameter. The default path is "<pref base drive>/rfo-
basic/data/tts.wav". The statement does not return until the speech synthesis is complete, but there is
no guarantee the file-write is finished. If a previous TTS.speak is still speaking, this statement will not
start until that speech completes.
TTS.stop
Waits for any outstanding speech to finish, then releases Android's text-to-speech engine. Following
TTS.stop, if you want to run TTS.speak or TTS.speak.toFile again, you will have to run TTS.init again.
Speech To Text (Voice Recognition)
The Voice Recognition function on Android uses Google Servers to perform the recognition. This means
that you must be connected to the Internet and logged into your Google account for this feature to
work.
There are two commands for Speech to Text: STT.listen and STT.results.
STT.listen starts the voice recognition process with a dialog box. STT.results reports the interpretation
of the voice with a list of strings.
The Speech to Text procedures are different for Graphics Mode, HTML mode and simple Console Output
mode.
STT.listen {<prompt_sexp>}
Start the voice recognize process by displaying a "Speak Now" dialog box. The optional prompt string
expression <prompt_sexp> sets the dialog box's prompt. If you do not provide the prompt parameter,
the default prompt "BASIC! Speech To Text" is used.
Begin speaking when the dialog box appers.
The recognition will stop when there is a pause in the speaking.