@lumiastream/wakeword
v1.1.2
Published
A wake word detection library using Vosk and SoX for real-time voice recognition.
Readme
LumiaWakeWord
A wake word detection library using Vosk and SoX for real-time voice recognition.
Features
- Real-time wake word detection
- Multi-platform support (Windows, macOS, Linux)
- Audio device selection (especially useful for Windows)
- Confidence threshold filtering
- Dynamic grammar updates
Installation
npm install @lumiastream/wakewordQuick Start
import { startWakeWord, listAudioDevices } from "@lumiastream/wakeword";
// List available audio devices
const devices = await listAudioDevices();
console.log("Available devices:", devices);
// Start wake word detection
const wakeWord = startWakeWord({
grammar: ["hello", "lumia", "computer"],
confidence: 0.7,
device: "0" // Optional: specify audio device
});
// Handle detections
wakeWord.stdout.on("data", (data) => {
const lines = data.toString().split("\n");
for (const line of lines) {
if (line.startsWith("voice|")) {
const word = line.split("|")[1];
console.log(`Wake word detected: ${word}`);
}
}
});Audio Device Selection
Windows Users
Windows users often need to select the correct audio input device. Use these commands to find and test devices:
# List all available audio devices
npm run list-devices
# Interactive device testing
npm run test-devices
# Use a specific device
AUDIO_DEVICE=1 npm startSetting the Audio Device
Method 1: Environment Variable
set AUDIO_DEVICE=1
npm startMethod 2: Programmatically
startWakeWord({
device: "1",
grammar: ["hello", "lumia"]
});See AUDIO_DEVICES.md for detailed device configuration guide.
API Reference
listAudioDevices()
Returns a Promise that resolves to an array of available audio devices.
const devices = await listAudioDevices();
// Returns: [{ id: "0", name: "Microphone (Realtek)" }, ...]startWakeWord(options)
Starts the wake word detection process.
Options:
device(string): Audio device ID to usesoxPath(string): Path to SoX binary (optional)sampleRate(number): Sample rate, default 16000grammar(string[]): Array of wake words to detectconfidence(number): Confidence threshold (0-1), default 0.7
Returns: ChildProcess instance
Scripts
npm run list-devices # List available audio devices
npm run test-devices # Interactive device testing
npm start # Start wake word detectionExample
Run the included example:
node example.jsDependencies
- Vosk - Speech recognition toolkit
- SoX - Sound processing tool
- Vosk model included: vosk-model-small-en-us-0.15
Platform Notes
Windows
- Default uses device "0" if not specified
- Use
npm run test-devicesto find the correct device - USB microphones may appear as separate devices
macOS/Linux
- Uses system default audio input automatically
- Device selection usually not needed
Troubleshooting
No audio detected on Windows:
- Run
npm run test-devicesto find the correct device - Set
AUDIO_DEVICEenvironment variable
- Run
Poor recognition quality:
- Adjust confidence threshold (lower = more sensitive)
- Try different audio devices
- Ensure microphone is not muted
Device not found:
- Ensure microphone is connected before starting
- Check system audio settings
SoX Binaries
Pre-compiled SoX binaries are included for all platforms. Source: https://github.com/zackees/static-sox/tree/main/bin
License
See LICENSE file for details.
