Your robot has an on-board speaker. You've already made some sounds using it but they've used simple tones. We can actually play digital recorded sounds from 'WAV' files.
Your robot has an on-board speaker. You've already made some sounds using it but they've used simple tones. We can actually play digital recorded sounds from 'WAV' files.
We're going to use an online sound effect creator to make some sound effects. Go to https://sfxr.me/
To get an idea of the sort of sounds it can create, click on the Random button, or try clicking one one of the sound types below this button. For example,clicking on 'Explosion' might be a good starting point for a crash sound for your robot.
By changing the sliders on the right you can customise the sound. Spend a few minutes experimenting with these sliders. If you want to see some tips, read on ...
The top 'Envelope' sliders affect the length of your sound. The start of the sound is called the 'attack', the middle is called the 'sustain', and the end is called the 'decay'. You can adjust all of these independently.
The 'frequency' sliders below this affect the pitch. If you set a 'slide', the pitch will change as the note plays. This is good for something like a siren sound.
The 'retrigger' will make the sound repeat. This is also useful for siren-type sounds.
The 'gain' controls the loudness of the sound
You need to create three sound effects:
When you've created each sound, you'll need to download the 'wav' files. Make sure you've selected the '8 bit' and '6k' options shown and then click on the filename to download.
To upload your files to the robot, you'll need to click on the 'Files' tab.
If you click on the 'Refresh' icon shown, you'll see what existing files are stored in your robot's memory.
Use the button shown to upload each file.
To see and select the 'WAV' file you have downloaded, you'll need to select 'All Files' as shown.
To play your sound you are going to need to import the "wavplay" library.
Once you have done this it is as simple as calling the wavplay() function with the file you created as the parameter.
Give it a try by running your program. The tiny speaker on the robot is pretty quiet but hopefully you can recognise your sound!
from wavplay import *
wavplay('sound.wav')
You're now going to make a remote-control robot with sound effects. This is what it should do: