Scratch coding offers many ways to enhance projects, and one of them is by adding music! So today you and your child will learn how to create music in Scratch. There are many options for adding customized and pre-recorded sounds.
For live expert guidance making fun games and animations with coding, join our award-winning free Scratch classes, designed by professionals from Google, Stanford, and MIT.
Discover How to Create Music in Scratch
To add music and sounds to your Scratch project you have many options. One of the places to start is the “Sounds” panel in the upper left.
Scratch has hundreds of pre-recorded sounds you can add to your project. To do so, click the “add sound” symbol in the bottom left. Then you’ll see all the options available! You can scroll through them or search in categories like “Animals”, “Percussion” or “Wacky”.
How to Upload Music to Scratch
Another option is to upload a sound or music file from your computer. Hover over the “add sound” symbol, and then click the “upload” option at the top of the choices that appear. Now you can select the file from your computer that you want.
If you would like to record a sound, you can do that as well! Hover over the “add sound” symbol, but this time select “record”, which is the third option from the top. Make sure to enable microphone access. Then click the button in the pop up screen and start recording.
Once your sound is in Scratch, you have many options for customization. You can change the speed and volume, or play around with effects like fade in/out.
How to Create a Music Loop in Scratch
In your project, you may want to create a music loop. The first block you’ll need is “when green flag clicked” from the Events section. Next you’ll need a block to execute the loop from the Control section. If you want the sound to loop over the entire project, use the “forever” block. If you only want to loop a certain number of times, then use the “repeat” block and change the number to what you want it to be.
Finally, within your loop, you want to put a “play sound until done” Sound block. This makes sure the entire soundtrack finishes before looping again. If you want more sounds to select from the drop down, you can add more options in the “Sounds” panel as described earlier in this post. Your final loop looks like this.
Using the Instruments Extension in Scratch
Back on the “Code” tab, the “Music” extension is another way to add sound. The extension button is in the bottom left corner.
Now you have a whole new set of drag and drop blocks to use. You can select percussion instruments ranging from the snare drum to the cowbell. A different block lets you select instruments like piano or clarinet. Other blocks let you set the tempo or the duration of a note.
One way to get creative is the play notes block. The first note specifies the pitch of the block. The larger the number, the higher the note. You can also use the interactive piano that pops up to test out the different notes. The second number in this block lets you set how long to play the note.
Tips for Common Bugs Encountered While Trying to Add Sound
1. Ensure your sound files are supported and properly imported
Before adding music, make sure the sound file is in a format that Scratch supports, like MP3 or WAV. If the file doesn't import correctly, try converting it to one of these formats using a free online converter.
2. Check volume levels and synchronization
Use the “set volume to” and “play sound until done” blocks to manage volume and synchronization. Adjust the volume to a suitable level so the music doesn't overpower other sounds in the project.
3. Avoid overloading your project with multiple sounds
Manage sound files carefully to prevent your project from becoming too complex or laggy. Only use essential sounds and make sure to stop one sound before starting another if they should not overlap. Place the "Stop All Sounds" block before the "Play Sound" block to ensure only one sound plays at a time.
Check Out Cool Scratch Projects with Music
Need a few ideas for inspiration? Explore some awesome Scratch projects that enhance their impact with music.
- Pumpkinoids uses laser sounds to complement the visuals. This project was made in Create & Learn's Scratch Ninja class.
- Egga's Time Traveling Adventure uses sounds to add suspense. This project was made in our Accelerated Scratch class.
- Macintosh 128K uses computer sounds as a special effect. This project was made in our Scratch Ninja class.
Create Music in Scratch
You can take a Scratch project you already have and add your own musical creations to it, or start a fresh project! Our Scratch classes and Scratch camps are a great way to learn how to build stories to accompany musical additions. Up next, find out how to make a jumping game in Scratch.
Written by Sophie Andrews, a Create & Learn instructor. Sophie Andrews is a student at Stanford University studying Math and Computational Sciences. She loves teaching and is a teaching assistant for Stanford's introductory computer science classes. Her work focuses on data science. Last year she built the online National Vote Trackers for The Cook Political Report, and she currently leads the Data Team at The Stanford Daily. She's also interned with the FCC and the National Renewable Energy Lab.