- Practice
- About 13 min
- 5 practice questions
Scratch: adding sound and a 'Hello' program
Play and change a sprite's sound in the Sounds tab, start a script with a key press, make a sprite say 'Hello' with sound, and save and run the project.
If something looks wrong, please tell us.
By the end of this lesson you can
- Use the Sounds tab to play, choose and add sounds.
- Start a script with 'when space key pressed'.
- Build the textbook's program that makes a sprite say 'Hello' with sound.
- Save a project and run it with the green flag.
Cinema is powerful because it joins pictures and sound. In this last lesson your sprite gets a voice: it will play a sound when a key is pressed and say 'Hello' in a speech bubble. As before, menu names may differ slightly between versions of Scratch; look for the same category names.
Adding sound to a sprite
- Click Sprite1 in the sprite list, then click the Sounds tab.
- Play the meow sound that is already there. To use another, click the speaker (sound library) icon and choose one.
- Go back to the Scripts tab (called the Code tab in newer versions). From Events, drag when space key pressed to the script area.
- From the Sound category, add a play sound block under it and pick your sound from the drop-down list. Newer versions offer 'start sound' and 'play sound until done' instead.
- Press the space bar to run it.
Notice that this script starts with a key press, not the green flag. Scratch scripts begin with an event: something that happens, such as a flag click, a key press or a click on the sprite. One sprite can have several scripts, each started by a different event.
The 'Hello' program
A sprite that says Hello with sound
- Events: when green flag clicked Starts the script
- Looks: say Hello A speech bubble shows 'Hello'
- Sound: play sound Choose a hello sound from the audio file
- File: Save Keep the project in your folder
- Click the green flag Run and watch the output
In detail: (1) click Events and drag the green-flag block to the script area; (2) click Looks and drag a say block under it; (3) type Hello in the say block; (4) click Sound and drag a play sound block underneath, choosing a hello sound (you may need to record one or choose one from the library); (5) save the project from the File menu, choosing your project folder; (6) click the green flag and the sprite shows 'Hello' in a speech bubble and plays the sound.
Worked example 1: which event?
Question: You want a cat to meow when the space bar is pressed and to walk forward when the green flag is clicked. How many scripts do you need, and how do they start? Reasoning: two different events mean two scripts on the same sprite: one beginning when space key pressed with a play sound block; one beginning when green flag clicked with go to x: 0 y: 0 and move blocks.
Worked example 2: fixing a bug
Problem: Ravi's script is: when green flag clicked; say Hello for 2 seconds; play sound. He wants the sound to play while the bubble shows, but it plays only after the bubble disappears. Reasoning: blocks run from top to bottom, and 'say ... for 2 seconds' waits 2 seconds before moving on. Fix: put the sound first using a block that does not wait (for example 'start sound' in newer versions), then 'say Hello for 2 seconds'; or use the plain 'say Hello' block, which does not wait. Now the speech and the sound happen together.
Every script starts with an event (green flag, key press). Looks → say shows a speech bubble; Sound → play sound plays audio. Save from the File menu, then run with the green flag.
Key takeaways: the Sounds tab manages a sprite's sounds; event blocks decide when a script runs; blocks run in order from top to bottom. With movement, loops, costumes, speech and sound you have all the pieces of a simple cartoon or game, the visual communication this unit is about.
Check your understanding
-
1. Which tab do you open to play or change a sprite's meow?
- Costumes
- Sounds
- Stage
- File
Show answer
Answer: B. The Sounds tab lists a sprite's sounds, lets you play them and lets you choose new ones from the library.
-
2. To make the sprite show 'Hello' in a speech bubble, you use a block from which category?
- Motion
- Sound
- Events
- Looks
Show answer
Answer: D. The 'say' block is in Looks, which controls how a sprite appears, including speech bubbles. Sound plays audio.
-
3. A script begins with 'when space key pressed'. When does it run?
- When the space bar is pressed
- Only when the green flag is clicked
- Every time the computer starts
- When the file is saved
Show answer
Answer: A. An event block starts its script when that event happens, here a press of the space bar.
-
4. Blocks in a Scratch script run:
- All at once in random order
- From bottom to top
- From top to bottom, in order
- Only the first block
Show answer
Answer: C. Scratch runs the blocks of a script one after another from top to bottom, which is why order matters.
-
5. In the textbook's Hello program, what is the last step before running?
- Delete the sprite
- Save the project from the File menu
- Change the stage to black
- Remove the green-flag block
Show answer
Answer: B. After adding the say and play sound blocks, the project is saved from the File menu, and then the green flag is clicked to run it.
Sign in to keep track of the lessons you finish.