Build a Voice Command Assistant with Node.js on Raspberry Pi
Build a voice-controlled assistant on a Raspberry Pi 3 using Node.js, PocketSphinx for speech recognition, and Node-RED for command orchestration.
Architecture
Three components communicate via MQTT:
- shirka_ears: Listens to microphone, publishes voice commands
- shirka_voice: Receives messages, converts to speech, plays audio
- Node-RED: Routes commands and responses between components
The Ears
Speech recognition using PocketSphinx:
npm install pocketsphinx
Listen for commands and publish to MQTT:
const mqtt = require('mqtt');
const ps = require('pocketsphinx');
const client = mqtt.connect('mqtt://localhost');
ps.listen()
.on('data', (command) => {
client.publish('shirka/commands', command);
});
The Voice
Text-to-speech pipeline using pico2wave and omxplayer:
sudo apt-get install libttspico-utils omxplayer
Subscribe to MQTT, generate speech, play audio:
const mqtt = require('mqtt');
const { exec } = require('child_process');
const client = mqtt.connect('mqtt://localhost');
client.subscribe('shirka/responses');
client.on('message', (topic, message) => {
const text = message.toString();
exec(`pico2wave -w response.wav "${text}" && omxplayer response.wav`);
});
Node-RED Flow
Install Node-RED and MQTT broker:
sudo apt-get install mosquitto mosquitto-clients
npm install -g node-red
Create a flow that:
- Subscribes to
shirka/commands - Processes commands
- Publishes responses to
shirka/responses
Code
Full implementation: github.com/bustroker/bustroker.shirka