Sound Model Guide

Use a sound classification model from Teachable Machine to recognise sounds and make Marty respond in Blocks. This uses your computer or tablet's microphone, rather than Marty's noise sensor. Connect Marty when you want the robot to perform an action.

New to Teachable Machine? Start with its videos on gathering samples and training a model. For a model built directly in Blocks, see Machine Learning in Blocks.

Step 1: Create a sound classification model on Teachable Machine

  1. Open Teachable Machine and select Get Started.
  2. Choose Audio Project.
  3. Collect background-noise samples and examples of the sounds you want to distinguish, such as clap and whistle.
  4. Select Train Model, then test the model with new sounds before exporting it.

Step 2: Export your model from Teachable Machine

  1. Select Export Model in the Preview panel.
  2. Keep Tensorflow.js selected and choose Upload (shareable link).
  3. Select Upload my model. When the upload finishes, copy Your sharable link.

Teachable Machine export options with Upload shareable link selected

Copy the shareable model link after uploading

Copy the model link, which has the form https://teachablemachine.withgoogle.com/models/…/. You do not need to copy the JavaScript code shown below it.

Step 3: Open Machine Learning in Blocks

  1. Open Blocks.
  2. Add and select your Marty device. Connect it if you want to use robot actions.
  3. Open the Machine Learning tab.
  4. Open the Add New Model menu at the bottom left and choose Load TM Model.

Step 4: Import your Teachable Machine model

Paste the shareable link into Paste TM model URL here, then select Load.

Load Teachable Machine Model dialog in current Blocks

Wait for the imported model to appear in the Models list. It is already trained, so you do not need to train it again in Blocks. Keep the same Marty device selected when you return to Code: the imported model belongs to that device in your project.

Step 5: Make classifications in Blocks

In Code, choose Machine Learning. Drag Load Machine Learning model into your program and select the imported model from its dropdown. The same block loads both image and sound models. Place it below when green flag clicked, then click the green flag to load it before using the prediction blocks.

Load an imported sound model when the green flag is clicked

Allow Blocks to use your microphone when prompted. Loading a sound model starts classification. Use turn classification off/on to pause or resume it.

The examples below use a model named Sound model with a clap class. Choose your own model and class names. These are alternative ways to respond to a prediction:

  • Event: attach an action below when received sound label: [class].
  • Boolean: use sound [class] detected as the condition of an if block. An if block checks once; put it inside a forever loop if you want to keep checking.
  • Label reporter: compare sound label with a class name using the = operator, then use that comparison as a condition.

Alternative sound prediction patterns using an event, an if condition, and a sound label comparison

Tick the checkbox beside sound label in the palette to display the latest label. It may be empty when no prediction meets the confidence threshold.

Step 6: Changing the confidence threshold (optional)

Use set confidence threshold to set the minimum confidence needed to report a label. The default is 0.5, or 50%. Increase it to require a more confident prediction, or lower it if your model rarely produces a label.

Blocks to pause sound classification and set the confidence threshold

To keep your imported model and code, save the project from Save/Load.

Task Runner