Implement play_wav, record_voice, and host-side voice assistant coordinator script

This commit is contained in:
Adolfo Reyna
2026-06-01 14:38:21 -04:00
parent f443da0352
commit 612ba63c59
3 changed files with 535 additions and 0 deletions
+48
View File
@@ -228,6 +228,29 @@ class MCPServer:
"volume": {"type": "integer", "description": "Volume of the tone from 0 to 100 (default 50)", "default": 50}
}
}
},
{
"name": "play_audio",
"description": "Play a standard WAV audio file on the speaker.",
"inputSchema": {
"type": "object",
"properties": {
"filename": {"type": "string", "description": "WAV file path to play (e.g. 'response.wav')"},
"volume": {"type": "integer", "description": "Volume from 0 to 100 (default 50)", "default": 50}
},
"required": ["filename"]
}
},
{
"name": "record_voice",
"description": "Record voice command from the microphone to a raw stereo PCM file.",
"inputSchema": {
"type": "object",
"properties": {
"duration_sec": {"type": "integer", "description": "Duration in seconds (default 4)", "default": 4},
"filename": {"type": "string", "description": "Destination file path (e.g. 'recording.pcm')", "default": "recording.pcm"}
}
}
}
]
},
@@ -429,5 +452,30 @@ class MCPServer:
play_tone(frequency=freq, duration_ms=duration, volume=vol)
return f"Played tone of {freq}Hz for {duration}ms at volume {vol}."
elif name == "play_audio":
filename = str(args.get("filename"))
vol = int(args.get("volume", 50))
vol = max(0, min(100, vol))
from audio_util import play_wav
success = play_wav(filename, volume=vol)
if success:
return f"Successfully played audio file '{filename}'."
else:
raise RuntimeError(f"Failed to play audio file '{filename}'. Check format (16kHz 16-bit PCM WAV recommended).")
elif name == "record_voice":
duration = int(args.get("duration_sec", 4))
filename = str(args.get("filename", "recording.pcm"))
# Clamp duration to a reasonable range
duration = max(1, min(15, duration))
from audio_util import record_audio
success = record_audio(duration_seconds=duration, filename=filename)
if success:
return f"Successfully recorded {duration} seconds of audio to '{filename}'."
else:
raise RuntimeError("Audio recording failed.")
else:
raise ValueError(f"Unknown tool: {name}")