Update some links, add navigation to top

Westside Robotics
2021-12-03 16:09:00 -08:00
parent e1b5740e40
commit fc13d82c11

@ -1,15 +1,17 @@
.
FTC Blocks can play short sounds on the Robot Controller (RC) and Driver Station (DS) phones. Here's a general guide to this fun and useful feature.
### Introduction
A [different tutorial](https://github.com/WestsideRobotics/FTC-DS-Speech/wiki) covers Text-to-Speech Telemetry that plays only on the DS phone or Driver Station -- also a fun and useful feature.
FTC Blocks can play short sounds on Robot Controller (RC) phones and Driver Station (DS) devices. Here's a general guide to this fun and useful feature.
A [different tutorial](https://github.com/WestsideRobotics/FTC-DS-Speech/wiki) covers Text-to-Speech Telemetry that plays only on the DS phone or Driver Hub -- also a fun and useful feature.
***
### Step 1 - Audio Files
Find or record your sound files. Blocks can play audio files in the popular **.wav** and **.mp3** formats. Some short samples are posted [here](https://drive.google.com/drive/u/2/folders/1wSuYg5JiL2xmUVx7tfV0vUvIK-ERtv7J).
Find or record your sound files. Blocks can play audio files in the popular **.wav** and **.mp3** formats. Some short samples are posted [here](https://github.com/FIRST-Tech-Challenge/WikiSupport/tree/master/FTC-sound-files). Click a file name and then the `Download` button.
Most laptop computers can easily make voice recordings.
@ -17,6 +19,8 @@ Most laptop computers can easily make voice recordings.
In Windows, the Sound Recorder program creates .wma files. Many free websites like [this one](https://audio.online-convert.com/convert-to-mp3) can convert your existing audio file into .wav or .mp3 format.
[<p align="right"><i>Return to Top</i>](#introduction)<p>
### Step 2 - My Sounds
In the top-level Blocks interface (list of OpModes), click on "**Sounds**" at the right side of the screen.
@ -27,18 +31,24 @@ This open a new Chrome tab called **My Sounds**, where you can upload and manage
<p align="center">[[/images/Playing-Audio-Files/0120-My_Sounds-menu.png|]]<p>
[<p align="right"><i>Return to Top</i>](#introduction)<p>
### Step 3 - SoundPool Menu
Leave the My Sounds tab open, and return to the first Chrome tab. Open a Blocks OpMode (old or new). At the left side, look under Android, and **SoundPool**.
<p align="center">[[/images/Playing-Audio-Files/0130-SoundPool-menu.png|]]<p>
[<p align="right"><i>Return to Top</i>](#introduction)<p>
### Step 4 - Initialize SoundPool
It's best to do this before waitForStart, to save time later.
<p align="center">[[/images/Playing-Audio-Files/0140-initialize-SoundPool.png|]]<p>
[<p align="right"><i>Return to Top</i>](#introduction)<p>
### Step 5 - Preload Sound
**Optional** to preload the sound file, which theoretically improves response for larger files. This is done with a **Repeat** Loop. Change the '**while**' to '**until**', and attach one of the **preloadSound** Blocks. There's one for the SoundResource class which (in 2019-2020) contains the memorable (!) Skystone sounds, and the other is for your own previously uploaded sound files.
@ -55,6 +65,8 @@ For safety and convenience, add a secondary condition to the Repeat Until loop:
<p align="center">[[/images/Playing-Audio-Files/0160-init-telemetry.png|]]<p>
[<p align="right"><i>Return to Top</i>](#introduction)<p>
### Step 6 - Play Sound
Now add the play Block where desired. Again, enter the exact audio filename.
@ -77,6 +89,8 @@ Windows Explorer gives a handy estimate of playback duration, rounded to the nea
Right-click on any column heading, and choose "Length" (not "Duration"). This helps when starting to determine the exact amount of timed pause needed by a sound clip.
[<p align="right"><i>Return to Top</i>](#introduction)<p>
### Use in Development
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.
@ -85,6 +99,8 @@ Even simple counting values can be indicated with a number of beeps, or with rec
Sounds are most practical in a test environment, without the extreme noise of a tournament.
[<p align="right"><i>Return to Top</i>](#introduction)<p>
### SoundPool Options
Review the **optional** green Blocks to adjust volume, rate and looping. Hover the cursor over each Block for instructions.
@ -93,20 +109,24 @@ Review the **optional** green Blocks to adjust volume, rate and looping. Hover t
Make these settings **before** playing the audio file.
[<p align="right"><i>Return to Top</i>](#introduction)<p>
### Other Notes
The sound plays back on **both** RC and DS phones. Make sure the phone **audio** volume is set high, not just the ringtone volume. Note that the REV Control Hub has no speakers.
The sound plays back on **both** RC phones and DS devices. Make sure the device **audio** volume is set high, not just the ringtone volume. Note that the REV Control Hub has no speakers.
The **.stop** command simply stops a currently playing sound file. It does not permanently disable SoundPool.
<p align="center">[[/images/Playing-Audio-Files/0190-stop.png|]]<p>
Sound files are stored on the RC phone, in a folder named FIRST/blocks/sounds. Here you will see all the files from the My Sounds listing.
Sound files are stored on the RC device, in a folder named FIRST/blocks/sounds. Here you will see all the files from the My Sounds listing.
For spoken audio that plays only on the Driver Station or DS phone, see this tutorial on [speech Telemetry](https://github.com/WestsideRobotics/FTC-DS-Speech/wiki).
For spoken audio that plays only on the Driver Hub or DS phone, see this tutorial on [speech Telemetry](https://github.com/WestsideRobotics/FTC-DS-Speech/wiki).
Special note... you may find that Android does not load or play the audio files instantly, especially the first time. It takes some practice to determine a file's response characteristics; still there can be unpredictable system-related variation. Consider pre-playing key sounds, for instant response later.
[<p align="right"><i>Return to Top</i>](#introduction)<p>
### Longer Playbacks
Some users have trouble playing audio files longer than about 6 seconds.
@ -127,6 +147,8 @@ Some [forums](https://stackoverflow.com/questions/43060791/android-soundpool-can
One FTC team wanted a theme song for autonomous. If the playing time can't be stretched enough, a last resort might be to break up the recording into **several sections** and play them in order. With great care this could be overlaid onto a completed/fine-tuned Linear OpMode autonomous. Or the autonomous could be re-written as a **state machine** in an Iterative OpMode, with the audio clips played in a **timed sequence**. Not so easy but maybe a good programming project! Learn about Blocks timers [here](https://github.com/WestsideRobotics/FTC-Timers/wiki).
[<p align="right"><i>Return to Top</i>](#introduction)<p>
***
<br><i>Questions, comments and corrections to: westsiderobotics@verizon.net</i>