Helping Kids Code Sounds into Their Programs - dummies

Helping Kids Code Sounds into Their Programs

By Camille McCue, Sarah Guthals

Teaching kids how to add sound to programs really brings them to life. Just a fair warning, after you teach your young coder how to add sounds, he may never want to stop playing the silly fart noise that he found! It might be helpful to have headphones, especially if you’re leading a group of young coders.

Sound file types

Just like with images, sound files are broken into three categories; uncompressed, lossless compression, and compressed (lossy compressed).

  • Uncompressed audio file types such as WAV (the audio file type most used on Windows computers) have no compression at all. These files are therefore larger, but have a high quality of playback, because every tone is represented within the file as it was originally recorded. Sound effects including creaky doors and howling wolves are usually WAV files.
  • Lossless compression audio file types do some compression, which allows the file to be a bit smaller, but the data is still 100 percent represented within the file.
  • Compressed audio files such as MP3 (the audio file type most used on devices universally) are the smallest of the audio files because information is removed from the file such as parts of sound that have the least effect on what humans can hear. This can cause MP3 audio files to have a reduction in quality compared to WAV audio files. This is how most music files are stored.

You most likely encounter WAV and MP3 file types in the digital sounds your coder works with.

Creating original sounds with code

Creating original sounds can be a lot of fun for you and your coder. You can create song clips that you sing yourself, or make silly noises that only you know how to make. Capturing those sounds digitally isn’t too difficult either.

One of the easiest ways is to use a mobile phone. Most mobile phones have a recorder app available in the app store. For example, on the iPhone you can use the free Voice Recorder and Audio Editor app to easily record something you say, and then share the MP3 that gets created either through AirDrop, email, or some other app that you use to get data from your phone to your computer.

If you’re writing a program in Scratch and want to create an original sound, you can choose the sprite that the sound is available to, then click the Sound tab, and click the microphone at the top center of the programming environment. A recorder opens, and as long as you have speakers on your computer, you can record an audio sound.

The first time you try creating a sound on Scratch, you have to give your web browser and Flash access to your microphone. You most likely see two popup windows asking for permission to use the microphone. Make sure that you do this with your young coder.

Finding sounds on the web

When you want to find high quality MP3 audio files on the Internet to use in your programs, it’s important that you only use audio files that you’re legally allowed to use. One of the best places to find sounds is on soundbible.com. soundbible.com has thousands of audio clips available completely for free, as well as some that you can pay for. If you go directly to SoundBible, you find audio clips that you can download that either have Attribution 3.0 or Public Domain licenses.

Attribution 3.0 simply means that you’re allowed to use the file (non-commercially), but you have to give credit to the original creator of the sound. So, if you use one of these sounds in a Scratch project, for example, include an attribution to the original sound creator in the description of your program when you publish it.

audio file credit
An example of giving credit to an audio file creator in Scratch.

Public domain audio files means that the audio file is free to use and you don’t have to give credit to the original creator of the sound.

It’s important to be careful what your young coder does regarding audio files. Many students want to use a popular song, so they record the song on a mobile phone and then upload the recording to their programs. Though this may be innocent, it’s important to teach your young coders about licenses and why they’re important. Encourage them to sing the song themselves or try playing the music on an instrument they’re learning.

Importing sounds into Scratch

Importing sounds into Scratch is very simple and can make the programs you write so much more exciting! After you have an MP3 file that you have legally downloaded onto your computer, open an existing project or start a new one in Scratch. Then, follow these steps to get your sound into your program:

  1. Choose a sprite that you want the sound to be associated with.
    For example, you can have a GIF of a sleeping cat and a sound of sawing wood. You can make the cat sound like it was snoring with the sound of sawing wood.
  2. Click the sprite that you chose, and then click the Sound tab in the center of the programming environment.
    You should already see a “pop” sound, which is the default sound that gets added to any sprite you upload. (If you want, you can delete this sound by clicking the x on the pop sound icon.)
  3. Click the folder with the up arrow and choose the MP3 file that you had previously downloaded.
    sprite sounds coding
    The upload button for adding a sound to a sprite in Scratch.
  4. (Optional) Add a snippet of code to play the sound until it’s done, and then insert the sound command into a forever loop.

    repeat sounds forever coding
    The code you can use to make sounds repeat forever in Scratch.

Importing audio into JavaScript

Importing sounds into App Lab can be done in just three easy steps:

  1. Click the App Lab button under the Start a New Project heading or open an existing project.
    Under the UI Controls category of blocks is a playSound block.

    playSound("URL", true);

    If you don’t see the placeholder code, you can write it yourself.

  2. Replace URL with the URL of the sound you want to use and then either leave the true as true, if you want your sound to keep repeating, or change it to false, if you want your sound to play once and then stop.
    If you’re getting your sounds from soundbible.com, then you have your sound downloaded on your computer. Just click the Show Blocks button at the top right of your programming environment, click the down arrow to the left of the URL in the playSound block, select Choose, and upload the sound file to Code.org. After you’ve done that, the URL is replaced with the file’s name:

    playSound("sawing-wood-daniel_simon.mp3", true);

  3. Click Run on the emulator on the left of your App Lab environment to hear your sound play.