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

corti

v2.1.0

Published

Replace window.SpeechRecognition with a mock object and automate your tests

Readme

Corti

Corti is a mock implementation of the browser’s SpeechRecognition API (aka webkitSpeechRecognition) for automated testing. It helps developers simulate speech recognition functionalities and test their applications in a controlled environment without relying on actual speech input.

💡 To easily use Speech Recognition in your own project, check out annyang.

Features

  • Mock SpeechRecognition API for testing purposes (can replace window.SpeechRecognition, window.webkitSpeechRecognition, window.mozSpeechRecognition, etc.)

  • Compatible with all JavaScript testing frameworks

  • Can be required (CJS), imported (ESM), or included via a script tag for testing in Node.js or in a browser

  • Written in TypeScript — ships with full type declarations

  • Adds additional functionality to the SpeechRecognition API to support programmatically simulating speech and checking the current status

Getting Started

Installation

Install corti as a dev dependency using npm / pnpm / bun / yarn / etc:

npm install --save-dev corti

Sample Usage

In node.js (ESM)

// Vitest example
import { SpeechRecognition } from 'corti';
import { describe, it, expect, beforeEach, beforeAll, afterAll, vi } from 'vitest';

beforeAll(() => {
  vi.stubGlobal('SpeechRecognition', SpeechRecognition);
});

afterAll(() => {
  vi.unstubAllGlobals();
});

describe('Mirror mirror on the wall', () => {
  let recognition;
  let spyFn;

  beforeEach(() => {
    recognition = new globalThis.SpeechRecognition();
    spyFn = vi.fn();
    recognition.maxAlternatives = 5;
    recognition.onresult = spyFn;
    recognition.start();
  });

  it('should call callback when called with a single sentence', () => {
    recognition.say('Hello world');
    expect(spyFn).toHaveBeenCalled();
    const event = spyFn.mock.calls[0][0];
    expect(event.results[0][0].transcript).toBe('Hello world');
  });

  it('should call callback when called with multiple sentences', () => {
    recognition.say(['Hello world', 'How are you?']);
    expect(spyFn).toHaveBeenCalled();
    const event = spyFn.mock.calls[0][0];
    expect(event.results[0][0].transcript).toBe('Hello world');
    expect(event.results[0][1].transcript).toBe('How are you?');
  });
});

In node.js (CJS)

// Jest example
const { SpeechRecognition } = require('corti');

beforeAll(() => {
  global.SpeechRecognition = SpeechRecognition;
});

test('SpeechRecognition', () => {
  const speech = new globalThis.SpeechRecognition();
  const spyFn = jest.fn();
  speech.onresult = spyFn;
  speech.continuous = true;
  speech.start();
  speech.say('Hello world');
  speech.say('Hello world');
  expect(spyFn.mock.calls.length).toBe(2);
});

In Browser (script tag)

<script src="https://cdnjs.cloudflare.com/ajax/libs/corti/2.0.0/corti.iife.min.js"></script>
<script>
  // Mock native SpeechRecognition
  window.SpeechRecognition = corti.SpeechRecognition;

  // Run some tests
  const recognition = new window.SpeechRecognition();
  recognition.onresult = () => console.log('I hear it!');
  recognition.start();
  recognition.say('Hello world');
</script>

For an example of how Corti is used in a real project, check out how SpeechRecognition is mocked and tested in Corti.

Methods Mocked

  • start()
  • abort()
  • stop()
  • addEventListener()

Attributes Mocked

  • interimResults
  • lang
  • continuous
  • maxAlternatives
  • onstart
  • onend
  • onresult
  • onsoundstart

Events Mocked

  • start
  • end
  • result
  • soundstart

Objects Mocked

  • SpeechRecognition
  • SpeechRecognitionEvent
  • SpeechRecognitionResultList
  • SpeechRecognitionResult
  • SpeechRecognitionAlternative

Extra Utility Methods Added To Mocked SpeechRecognition Object

  • isStarted()
  • say()

Types Exported

  • CortiSpeechRecognition — Extends the DOM's SpeechRecognition interface with say() and isStarted()

Author

Tal Ater: @TalAter

License

Licensed under MIT.