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 [[https://teachablemachine.withgoogle.com/train?action=onboardOpen&id=DFBbSTvtpy4|gathering samples]] and [[https://teachablemachine.withgoogle.com/train?action=onboardOpen&id=CO67EQ0ZWgA|training a model]]. For a model built directly in Blocks, see [[martyv2:userguides:martyblocks:machinelearning:start|Machine Learning in Blocks]]. ===== Step 1: Create a sound classification model on Teachable Machine ===== - Open [[https://teachablemachine.withgoogle.com/|Teachable Machine]] and select **Get Started**. - Choose **Audio Project**. - Collect background-noise samples and examples of the sounds you want to distinguish, such as **clap** and **whistle**. - Select **Train Model**, then test the model with new sounds before exporting it. ===== Step 2: Export your model from Teachable Machine ===== - Select **Export Model** in the Preview panel. - Keep **Tensorflow.js** selected and choose **Upload (shareable link)**. - Select **Upload my model**. When the upload finishes, copy **Your sharable link**. {{ :martyv2:userguides:martyblocks:teachablemachine:1.tmexport.png?nolink&550 |Teachable Machine export options with Upload shareable link selected}} {{ :martyv2:userguides:martyblocks:teachablemachine:2.tm-export2.png?nolink&600 |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 ===== - Open [[https://robotical.app/blocks|Blocks]]. - Add and select your **Marty** device. Connect it if you want to use robot actions. - Open the **Machine Learning** tab. - 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**. {{ :martyv2:userguides:martyblocks:teachablemachine:tm-import-url-2026.jpg?nolink&510 |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. {{ :martyv2:userguides:martyblocks:teachablemachine:tm-sound-load-2026.jpg?nolink&425 |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. {{ :martyv2:userguides:martyblocks:teachablemachine:tm-sound-responses-2026.jpg?nolink&375 |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. {{ :martyv2:userguides:martyblocks:teachablemachine:tm-sound-controls-2026.jpg?nolink&285 |Blocks to pause sound classification and set the confidence threshold}} To keep your imported model and code, save the project from **Save/Load**.