-
Notifications
You must be signed in to change notification settings - Fork 0
Home
.
This tutorial shows how FTC Blocks can play speaking audio on the DS phone or the REV Driver Station. ¡En Español también! Aussi en Français! ...and many other languages.
Spoken audio can provide helpful feedback to the programmers and robot operators, while the Op Mode is running. This can be more useful than audio on the Robot Controller, which may be hard to hear in competition. In any case, the REV Control Hub has no speakers.
A different tutorial shows how FTC Blocks can play short sounds (recorded audio clips) on the Robot Controller (RC) phone and Driver Station (DS phone or REV Driver Station).
Open any old or new OpMode. There isn't a Sample OpMode for this DS speaking feature. The Sample called "cvxcv" sends spoken text only to the Robot Controller (RC phone).
In the left side menu, open Utilities, then Telemetry. Click and drag out the purple Block "call Telemetry.speak". For now, don't use the larger Block with languageCode and countryCode.
Place that basic Block in your OpMode, where you want the speaking to happen.
Change the default "text" to the actual message that you want. The OpMode will use Android's Text-To-Speech (TTS) feature to convert your typed words into spoken audio.
The command Telemetry.speak begins playing the spoken message. The OpMode will immediately move to the next command. If the program ends soon, your message might not finished playing. Or, you might want the robot's next action to begin when the audio speech has finished.
So, you should manually allow time for your audio to play. Unlike the Blocks TTS feature for RC phone, there is no Boolean variable "isSpeaking" that becomes FALSE when the audio has finished playing.
You can estimate or measure the duration of the audio. This works fairly well, assuming the audio begins playing immediately.
The sleep() method is simple and will work, but no other new commands can begin during that time.
A better way to wait, is to use a Timer, like this:
It's optional for the Timer loop to include a printed message with audio playback status.
Timers in FTC Blocks are described in more detail at this tutorial.
If the audio playback is not starting immediately or after a consistent delay, see below for a possible workaround.
/Images/0120-My_Sounds-menu.png
Save and run your OpMode. Make sure you've turned up the Driver Station's audio volume (not the ringtone volume).
If the words don't sound the way you want, you can adjust the text. Here, clearly understood audio is probably more important than the exact spelling or punctuation of the typed text.
That's it! Enjoy this fun and useful feature of FTC Blocks.
This feature can also be valuable in debugging programs. For example:
Speak "drive forward 10 inches and stop" - did that happen? Speak "color sensor sees RED" (or BLUE) - was the sensor correct?
If your OpMode is not behaving as expected, audio feedback can help find the problem.
Sounds can be a very useful tool for programming and debugging. They can mark the transition from one autonomous action to another, often very hard to see. Different sounds can indicate certain conditions, such as encoder ranges or sensor values, or different stages in the program. Sometimes the robot is executing an unexpected or unknown operation, easily identified with a unique sound.
Even simple counting values can be indicated with a repeated "click" word, or by stating a number that increments in a loop.
TTS can even report values from variables -- numeric and Boolean! Use this for sensor data, to impress your friends and neighbors.
In Android, you can change the default language for TTS playback. This is not the same as the overall default language of the phone.
You will need an internet download, so close the FTC app and open a regular WiFi internet connection.
In the phone's Settings menu, open "Languages & input". Then choose "Text-to-speech output", not "Languages".
Next to Google TTS Engine, touch the Settings icon (small image of a gear).
Select "Install voice data", and choose the preferred language (and country/region dialect). You may also choose a preferred voice; touch each one to hear a sample.
After this download, navigate back and select the preferred language (that you downloaded).
That's it! That language will now be the default for TTS playback. Note the DS and RC phones could be set to different TTS languages, and would speak accordingly -- even in the same OpMode, even at the same time.
This will allow continued use of the basic purple "Telemetry.speak" Block in the instructions above. Your text can now be typed in that language, including special/native text characters -- copy them from other documents or, for example, from Microsoft Word's Insert Symbol. Numbers and Boolean values will be spoken in that language too!
You may have noticed a larger purple Block with languageCode and countryCode. This allows choosing from multiple TTS languages downloaded to the phone. Its use may be limited by memory allocation and other system-level factors.
If that large Block's drop-down menu does not offer the code you need, pull the green label away. In the bare grey field, type the country or region code needed. These codes follow the standard Android convention which can be found online.
In some cases, a language code alone will work, with no country code needed.
To refresh the pull-down menu after installing a new Android TTS language, pull that Block again from the menu. A previously placed Block will not update itself with added language codes.
Blocks has no Boolean variable "isSpeaking" for Text-To-Speech on the Driver Station. But that Boolean does exist for Robot Controller playback. So, you could play the same message on both devices, and use the RC Boolean to know when the messages have stopped playing.
For safety and convenience, add a secondary condition to the Repeat While loop. After the WaitForStart command, the secondary condition can be AND opModeIsActive. In the INIT section of your OpMode, use AND NOT isStopRequested -- don't use 'AND opModeIsActive' there, since you haven't yet pressed START (to make the OpMode active).
This parallel/Boolean technique assumes that both messages start and end at the same time. Ending should be fine, if you have not adjusted the playback speed of the RC text. You might find the RC audio starts slightly later than the DS audio. If you find the "echo" annoying, try a short (e.g. 50 millisecond) sleep between the two commands. Or turn down the audio on the RC phone -- but then you'll miss other RC audio signals and warnings. If using a REV Control Hub... there's no speaker -- perfect!
Audio cues for key OpMode actions are useful, but can slow down the overall sequence. Manually adding and removing these TTS messages takes a lot of work. Consider using a single Boolean variable to turn on and off all such TTS messages. When the OpMode is ready for smooth/continuous runs, simply change "useAudio" from TRUE to FALSE.
A more advanced solution is to set this Boolean during INIT, using the gamepad. A fun programming exercise!
A timed pause is essential if a sound plays in a tight loop. The audio file will start repeatedly, often so fast that it sounds like static noise or an irritating staccato of continuous starts.
Even if a gamepad button triggers playback in a repeat loop, a pause is still needed. The loop cycles faster than a human can release the button, causing that staccato of repeated starts. A "backlog" of waiting playbacks can build up; the sounds may continue spilling out long after the button has been released. Eventually the queued files will all play, and the sounds will stop.
The timed pause can be done with sleep() as shown below, or with a custom timer. A tutorial on Blocks timers is here.
.
Questions, comments and corrections to: westsiderobotics@verizon.net