npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

wake-word-command

v1.1.0

Published

A library for detecting wake words and extracting commands from speech

Downloads

39

Readme

Wake Word Command

A JavaScript library for wake word detection and command extraction using the Web Speech API.

Table of Contents

Features

  • Wake word detection using the Web Speech API
  • Command extraction after wake word detection
  • Configurable language support
  • Event-based architecture with callbacks
  • TypeScript support
  • Configurable logging levels

Installation

npm install wake-word-command

Usage

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");

Example: Voice-Controlled Todo List

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:

  • "Hey todo, add buy groceries"
  • "Hey todo, add call mom"
  • "Hey todo, remove 1"
  • "Hey todo, delete buy groceries"
  • "Hey todo, clear all"

API Reference

createWakeWordDetection(options)

Creates a new wake word detection instance.

Parameters

| 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 |

Returns

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 |

Example

const wakeWord = createWakeWordDetection({
  wakeWord: "hey assistant",
  language: "en-US",
  logLevel: "info",
  onWakeWordDetected: () => console.log("Wake word detected!"),
  onCommand: (command) => console.log("Command:", command),
});

Callback Functions

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 transcription

onCommand(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 message

Browser Support

This library uses the Web Speech API, which is supported in modern browsers:

  • Chrome (desktop and mobile)
  • Edge
  • Safari (desktop and mobile)

Note: Firefox does not currently support the Web Speech API's speech recognition feature.

License

MIT

Contributing

Contributions are welcome! Please read our Contributing Guidelines for details on our code of conduct and the process for submitting pull requests.