Sound effects
Invent Logo

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.

Sound effects
Creating your sounds

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 ...

Creating your sounds
Adjusting the length

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.

Adjusting the length
Adjusting the pitch

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.

Adjusting the pitch
Repeating sounds

The 'retrigger' will make the sound repeat. This is also useful for siren-type sounds.

Repeating sounds
Loudness

The 'gain' controls the loudness of the sound

Loudness
Sound effects

You need to create three sound effects:

  • A 'startup' sound when you robot starts moving
  • A 'crash' sound for when your robot hits something
  • A 'success' sound when you rescue your astronaut
  • A 'siren' sound for when you activate police mode

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.

Sound effects
The file manager

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.

The file manager
Uploading sounds

Use the button shown to upload each file.

Uploading sounds
Selecting the file

To see and select the 'WAV' file you have downloaded, you'll need to select 'All Files' as shown.

Selecting the file
Playing Sounds

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')
The challenge

You're now going to make a remote-control robot with sound effects. This is what it should do:

  • If you starting moving forward, you should play the 'startup' sound
  • If you hit something you should play the 'crash' sound (you'll need the obstacle sensor for this)
  • Button 'A' should active the 'success' sound when you've collected the astronaut
  • Button 'B' should activate the 'siren' sound for when you need to be in 'police mode'!