Give the practice tracker a recorder: record a few seconds of today's practice, play it back, and see how long it was. The recording only exists once the user stops recording, so the app uses it in that event, not before.
Musicians record themselves because you hear things on a recording you miss while playing. Voice notes, language apps and podcasts all start with the same three parts: record, keep, play back.
The practice tracker from the first lesson adds up your minutes. Today it also records a short clip of your practice, so you can hear how it went.
A Recorder object records up to 20 seconds with the microphone (● to record, ■ to stop), or lets the user 🎵 Choose a sound file instead.
When the user stops (or chooses a file), the event Mic finishes a recording runs, and Mic.sound is the recording.
A Sound object can play it back: Set Playback sound to the one namedMic.sound.
Record your instrument, humming or clapping, not other people. Recordings stay in this browser: nothing is sent anywhere. Headphones help in a busy room.
How this lesson works: See it, Build, Check, Make it yours
See it: Try the finished thing first, so you know what you are building.
Build: Watch the short clip, then do the steps. Your app carries on from the step before.
Check: A quick check that the idea has stuck.
Make it yours: Change your app on purpose, then try it on someone.
Make your prediction first. Help opens once you've locked it in.
See itTry the finished thing first, so you know what you are building.
Try the finished app
Click ● and allow the microphone when the browser asks. Play, hum or clap for a few seconds, then click ■.
A player appears with your recording, and the app says how long it was. Press ▶.
Drag the two handles under the recorder to trim the start and end, then play it again.
No microphone, or it's blocked here? Click 🎵 Choose on the recorder and pick a sound file from your computer: the app treats it just like a recording.
Try it yourselfYour edits are saved in this browser.
BuildWatch the short clip, then do the steps. Your app carries on from the step before.
Build 1: a Recorder
+ Add object, Recorder. Rename it Mic and put it under the total (x 229, y 230, width 342).
In its Properties, tick Allow microphone in this app.
Run it, click ●, record a few seconds, then ■ (or 🎵 Choose a sound file). The recorder can play it back itself, but nothing else in the app knows about it yet.
A Recorder object · Sound on for the voiceoverVoice:
Try it yourselfYour edits are saved in this browser.
A Recorder called Mic.
Run your program. This ticks when your code does all of the above.
BuildWatch the short clip, then do the steps. Your app carries on from the step before.
Build 2: play it back
+ Add object, Sound. Rename it Playback, put it under the recorder (x 229, y 350, width 342) and untick Visible at start. A new Sound starts with a built-in tune, so it stays hidden until there's a recording.
Add an event: Mic, Mic finishes a recording, with two actions:
Playback, Set Playback sound to the one namedMic.sound
Playback, Show Playback
Run it, record, stop, and press ▶ on Playback.
There are two "set sound" actions. Set sound to picks one of the app's sounds while you design. Set sound to the one named works it out while the app runs, from a recording or a name, just like the two picture actions in Draw how you showed it.
Use the recording when it's finished · Sound on for the voiceoverVoice:
Try it yourselfYour edits are saved in this browser.
When Mic finishes a recording, Playback gets it (the one named Mic.sound) and is shown.
Run your program. This ticks when your code does all of the above.
BuildWatch the short clip, then do the steps. Your app carries on from the step before.
Build 3: how long was it?
Add a Text called LengthText under Playback (x 229, y 412, width 342), with no text.
In Mic finishes a recording, add Set LengthText text to"Recorded "&round(Mic.length) &" seconds"
Run it and record twice, once short and once long.
Try it yourselfYour edits are saved in this browser.
A text LengthText says how many seconds were recorded, when the recording finishes.
Run your program. This ticks when your code does all of the above.
CheckA quick check that the idea has stuck.
Check: when does the recording exist?
Nib wanted Playback ready from the start.
Try it on the recorder before you answer.
Nib's Playback never plays the recording, even after recording. Click the line where Nib first goes wrong.
Make it yoursChange your app on purpose, then try it on someone.
Make it yours: play it straight away
Play the recording back automatically: add Playback, Play Playback at the end of Mic finishes a recording.
More ideas: add the recording's length to the minutes practised, or a message when a recording is under 3 seconds ("Try a longer one").
Try it yourselfYour edits are saved in this browser.
The recording plays by itself as soon as recording finishes.
Run your program. This ticks when your code does all of the above.
Lesson done. You've finished every step you need.
Now you can
Add a Recorder and use the recording it makes.
Use something the user makes in the event that runs when it's ready.
Play a recording back with a Sound and show how long it was.
Students add a recorder to the practice tracker: a Recorder (microphone allowed), a hidden Sound that gets the recording in Mic finishes a recording and is then shown, and a line with the recording's length. Nib sets the Sound from Mic.sound when the screen starts, before anything is recorded, so it never plays. Make it yours plays the recording as soon as it's ready. About 40 minutes.
I can add a Recorder and use the recording it makes.
I can use something the user makes in the event that runs when it's ready.
I can play a recording back with a Sound and show how long it was.
Before class
This lesson starts from the finished practice tracker (Level 3 for the Recorder) and completes the Pictures from the user unit: a drawing, a photo, now a recording. Each is used in the event that runs when it's ready.
Microphone: off unless Allow microphone is ticked in the Recorder's properties, and the browser asks too. Some school devices block microphones; 🎵 Choose on the recorder picks a sound file instead (MP3, M4A, WAV and similar, about 5 MB at most, with Allow microphone off too) and runs the same event, so every student can finish. Recordings stay in this browser (nothing is uploaded), up to 20 seconds each.
Record instruments, humming or clapping, not other people. Headphones help, and so does spreading out: a room of microphones picks up everyone.
Playback starts hidden because a new Sound always has a built-in tune until something replaces it; the recording event shows it.
Trimming only changes which part plays; the whole recording is kept, so the handles can be dragged back out. Playback got Mic.sound when recording finished, so it plays the recording as it was then.
Running the lesson
Before Try: agree what to record (instruments, humming, clapping) and that headphones go on.
Build 2: ask when Mic.sound has a value. Answer before building the event.
Check: vote on Nib's line before revealing.
The hard part (on purpose)
Students expect to set up Playback once, at the start. The recording doesn't exist until the user stops, so ask: at the moment this action runs, has anything been recorded yet?
When students get stuck
The recorder says the microphone is off for this app. Ask: Is Allow microphone ticked in Mic's properties? Did the browser ask, and was it allowed? Fix: Tick it, then allow the microphone when the browser asks. If it's blocked on this computer, use 🎵 Choose to pick a sound file instead.
Playback plays a tune, not the recording. Ask: Which set-sound action did you use? Fix: Use Set Playback sound to the one named, with Mic.sound.
Playback never appears. Ask: Is there a Show Playback in the recording event? Fix: Add Show Playback after setting its sound.
Stretch and support
Stretch: Keep every recording: a list Recordings, Add Mic.sound to it when a recording finishes, and a List object that shows them (each shows as 🔊 Recording). Data apps does this properly with a table and a sound field.
Support: Do Build 2 together; it's the one with the idea in it.
Where it leads
Next: Creature stats. Using something in the event that runs when it's ready comes back with every kind of user input.
What each step is for
Try the finished app: Recording, then hearing it play back and seeing its length, shows the three parts to build: record, keep, play.
Build 1: a Recorder: A Recorder is an object like any other, but the microphone stays off unless the app allows it and the user agrees, because a microphone is private.
Build 2: play it back: The recording exists only once the user stops, so the event that runs then is where the app can use Mic.sound.
Build 3: how long was it?: Mic.length is worked out from the recording, so like Mic.sound it has a value only once recording has finished.
Check: when does the recording exist?: Asking when Mic.sound has a value, and what trimming changes, separates the recording from how it's played.
Make it yours: play it straight away: Adding Play to the same event makes the app react the moment the recording is ready, with no extra click.