
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
wake-word-command
Advanced tools
A library for detecting wake words and extracting commands from speech
A JavaScript library for wake word detection and command extraction using the Web Speech API.
npm install wake-word-command
import { createWakeWordDetection } from "wake-word-command";
const wakeWordDetection = createWakeWordDetection({
wakeWord: "hey computer",
language: "en-US",
logLevel: "info", // Optional: Set log level (none, error, warn, info, debug, all)
onWakeWordDetected: () => {
console.log("Wake word detected!");
},
onCommand: (command) => {
console.log("Command:", command);
},
onError: (error) => {
console.error("Error:", error);
},
});
// Start listening
wakeWordDetection.start();
// Stop listening
wakeWordDetection.stop();
// Change wake word
wakeWordDetection.setWakeWord("hey assistant");
// Change language
wakeWordDetection.setLanguage("es-ES");
// Change log level
wakeWordDetection.setLogLevel("debug");
Here's a practical example of using the library to create a voice-controlled todo list:
import { createWakeWordDetection } from "wake-word-command";
// Create a simple todo list UI
const todoList = document.createElement("ul");
document.body.appendChild(todoList);
// Create the wake word detector
const wakeWord = createWakeWordDetection({
wakeWord: "hey todo",
onWakeWordDetected: () => {
// Show a visual indicator that the system is listening
document.body.classList.add("listening");
},
onCommand: (command) => {
// Remove the listening indicator
document.body.classList.remove("listening");
// Process the command
const cmd = command.toLowerCase();
if (cmd.includes("add")) {
// Extract the todo item text
const itemText = cmd.replace("add", "").trim();
if (itemText) {
const li = document.createElement("li");
li.textContent = itemText;
todoList.appendChild(li);
}
} else if (cmd.includes("remove") || cmd.includes("delete")) {
// Extract the item number or text to remove
const itemToRemove = cmd.replace(/remove|delete/, "").trim();
const items = Array.from(todoList.children);
const index = parseInt(itemToRemove) - 1;
if (!isNaN(index) && items[index]) {
items[index].remove();
} else {
// Try to find by text
const item = items.find((li) =>
li.textContent.toLowerCase().includes(itemToRemove)
);
if (item) item.remove();
}
} else if (cmd.includes("clear") || cmd.includes("clear all")) {
todoList.innerHTML = "";
}
},
});
// Add some basic styles
const style = document.createElement("style");
style.textContent = `
.listening::after {
content: '🎤 Listening...';
position: fixed;
top: 20px;
right: 20px;
background: #4CAF50;
color: white;
padding: 10px 20px;
border-radius: 20px;
}
`;
document.head.appendChild(style);
// Start listening
wakeWord.start();
Try these voice commands:
createWakeWordDetection(options)Creates a new wake word detection instance.
| Parameter | Type | Required | Description |
|---|---|---|---|
| options | Object | Yes | Configuration options |
| options.wakeWord | string | Yes | The wake word to detect |
| options.language | string | No | Language code (default: 'en-US') |
| options.logLevel | string | No | The log level for console output |
| options.onWakeWordDetected | Function | No | Callback when wake word is detected |
| options.onTranscription | Function | No | Callback with current transcription |
| options.onCommand | Function | No | Callback with extracted command |
| options.onCommandTimeout | Function | No | Callback when command timeout occurs |
| options.onError | Function | No | Callback when an error occurs |
| options.commandTimeoutMs | number | No | Timeout duration in milliseconds for command detection |
An object with the following methods:
| Method | Description |
|---|---|
start() | Start listening for the wake word |
stop() | Stop listening for the wake word |
pause() | Pause listening for the wake word |
resume() | Resume listening for the wake word |
setWakeWord(wakeWord) | Change the wake word |
setLanguage(language) | Change the language |
setLogLevel(logLevel) | Change the log level |
isSupported() | Check if speech recognition is supported |
const wakeWord = createWakeWordDetection({
wakeWord: "hey assistant",
language: "en-US",
logLevel: "info",
onWakeWordDetected: () => console.log("Wake word detected!"),
onCommand: (command) => console.log("Command:", command),
});
onWakeWordDetected()Called when the wake word is detected. No parameters.
onTranscription(text)Called with the current transcription as it's being spoken.
text (string): The current transcriptiononCommand(command)Called when a complete command is detected.
command (string): The extracted command (text after the wake word)onCommandTimeout()Called when no command is detected within the timeout period (default: 3 seconds) after the wake word is detected. This indicates that the system is returning to listening for the wake word.
onError(error)Called when an error occurs.
error (string): The error messageThis library uses the Web Speech API, which is supported in modern browsers:
Note: Firefox does not currently support the Web Speech API's speech recognition feature.
MIT
Contributions are welcome! Please read our Contributing Guidelines for details on our code of conduct and the process for submitting pull requests.
FAQs
A library for detecting wake words and extracting commands from speech
The npm package wake-word-command receives a total of 6 weekly downloads. As such, wake-word-command popularity was classified as not popular.
We found that wake-word-command demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.