By Kevin McAleer, 5 Minutes
Page last updated November 24, 2026

SAM can speak. Now we pick a voice for the buddy and make it announce the door. This is status buddy stage 3.
SAM has a few settings that change how it sounds. Kev’s post lists them:
| Setting | Range | Effect |
|---|---|---|
pitch |
0 to 255 | Higher values give a higher voice |
speed |
0 to 255 | Higher values give slower speech |
mouth |
0 to 255 | The mouth shape, which affects the vowels |
throat |
0 to 255 | The throat shape, which affects the timbre |
Try two different characters back to back:
from sam import Sam
sam = Sam(pin=0)
# A normal robot voice
sam.pitch = 64
sam.mouth = 128
sam.throat = 128
sam.say("I am a robot")
# A tiny robot voice
sam.pitch = 200
sam.mouth = 100
sam.throat = 100
sam.say("I am a tiny robot")
Every combination sounds a little different, so experiment. The defaults shown in sam.info() are a good place to come back to if you get lost.
Here the golden rule from lesson 5 earns its keep. Speaking takes time: SAM must render the speech before it plays. If we called sam.say() from the interrupt handler, we’d be doing a long job in a place that should be instant. So the handler still only sets a flag, and the main loop does the talking after it has debounced.
Here is the status buddy that senses, shows and talks. Run it and open and close the door.
from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
from sam import Sam
import time
DEBOUNCE_MS = 50
# --- hardware ---
reed = Pin(15, Pin.IN, Pin.PULL_UP) # 0 = magnet near = closed
i2c = I2C(0, scl=Pin(5), sda=Pin(4), freq=400000)
oled = SSD1306_I2C(128, 64, i2c)
sam = Sam(pin=0)
# The buddy's voice
sam.pitch = 64
sam.mouth = 128
sam.throat = 128
# --- state ---
changed = False
door_open = reed.value() == 1
open_count = 0
changed_at = time.ticks_ms()
def on_edge(pin):
global changed
changed = True
reed.irq(trigger=Pin.IRQ_FALLING | Pin.IRQ_RISING, handler=on_edge)
def draw_screen():
secs = time.ticks_diff(time.ticks_ms(), changed_at) // 1000
oled.fill(0)
oled.text("Status Buddy", 16, 0)
oled.hline(0, 10, 128, 1)
oled.text("DOOR", 40, 20)
oled.text("OPEN" if door_open else "CLOSED", 40, 32)
oled.text("for {}s".format(secs), 40, 44)
oled.text("Opened: {}".format(open_count), 0, 56)
oled.show()
draw_screen()
last_draw = time.ticks_ms()
sam.say("Status buddy ready")
while True:
if changed:
changed = False
time.sleep_ms(DEBOUNCE_MS)
now_open = reed.value() == 1
if now_open != door_open:
door_open = now_open
changed_at = time.ticks_ms()
if door_open:
open_count += 1
draw_screen() # show it first...
last_draw = time.ticks_ms()
if door_open: # ...then say it
sam.say("The door is open")
else:
sam.say("The door is closed")
if time.ticks_diff(time.ticks_ms(), last_draw) >= 1000:
draw_screen()
last_draw = time.ticks_ms()
time.sleep_ms(10)
We draw first and speak second, so the screen updates instantly and doesn’t wait for the voice.
Kev’s SAM post has plenty of ideas you can steal:
sam.pitch before each say().sam.say("Opened {} times".format(open_count)).Problem: The buddy speaks, but the screen is slow to update.
Solution: Make sure draw_screen() runs before sam.say(), as in the program above.
Why: SAM has to render the speech before it can play it. That is quick with the native renderer, but it is still time the screen would be waiting if you spoke first.
Problem: The buddy says the same thing twice on one open.
Solution: Check your debounce wait is still there, and that you compare now_open != door_open before speaking.
Why: A bounce that isn’t filtered looks like two separate openings.
Quick quiz 1 of 3
Which setting makes SAM’s voice higher?
pitch values give a higher-pitched voice. Higher speed values actually make speech slower.Quick quiz 2 of 3
Why does the buddy speak from the main loop rather than from the interrupt handler?
Quick quiz 3 of 3
What is the job of the optional 1K resistor?
Comments