annyang turns spoken phrases into function calls in two kilobytes
💬 Speech recognition for your site
At a glance
- What is it?
- annyang is a dependency-free JavaScript library that matches spoken phrases to callbacks, with a capture syntax for variable parts of a command. Version 3 rewrote it in TypeScript without growing it, and everything it can do is bounded by the browser underneath.
- Who is it for?
- annyang fits a site that wants a handful of spoken shortcuts alongside its existing interface, where two kilobytes and no dependencies matter more than controlling the recognition itself. Skip it when you need dictated prose rather than matched commands, or when one fixed phrase makes calling the browser interface directly the smaller job.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 44 days ago.
- What is it written in?
- Mainly TypeScript, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on September 15, 2026, and from our analysis. They are not legal advice.
DEEP OPEN-SOURCE ANALYSIS
Two kilobytes between your site and a voice command
annyang is a JavaScript library that lets visitors control a web page by speaking. It weighs two kilobytes, has no dependencies, and its entire job is turning what someone said into a call to a function you wrote.
It is a wrapper, and that is the correct thing for it to be. Browsers already ship speech recognition; what they do not ship is a pleasant way to say that the phrase "search for hats" should call your search handler with the word "hats". annyang supplies the matching layer and stays out of everything else.
The audience is anyone adding a voice affordance to an existing site: an accessibility alternative to clicking, hands-free control in a kitchen or workshop interface, a demonstration, a kiosk. It is not a transcription library. If you want a paragraph of dictated text rather than a matched command, this is the wrong shape of tool.
Commands are an object, and the interesting part is the asterisk
Defining behaviour means writing an object whose keys are phrases and whose values are functions. A key of hello calls its function when someone says hello. That much is unremarkable.
The capture syntax is what makes it usable. A key written as search for followed by an asterisk and a name matches anything after those words and passes it to the function as an argument. So a single command definition handles every possible search term, and your function receives the term rather than the whole utterance. That is a small piece of design doing a lot of work, because the alternative is either enumerating phrases you expect or writing your own parser over the raw transcript.
The rest of the surface is as small as the library. A function reports whether the browser supports speech recognition at all, another adds commands, another starts listening. Version 3 added named imports, so you can pull those three functions directly instead of reaching through a default export, which suits bundlers that eliminate unused code.
Structure worth noting: the support check exists as a public function at all. A library that ships a capability test is telling you the capability is not universal, and that the calling code is expected to handle its absence.
Installing it in whichever module system you already use
The package comes from the registry under its own name.
npm install annyangThe recommended integration uses standard modules, and the shape below is the whole of a working setup: check support, define commands, register them, start listening.
import annyang from 'annyang';
if (annyang.isSpeechRecognitionSupported()) {
// Let's define a command.
const commands = {
'hello': () => { alert('Hello world!'); },
'search for *term': (term) => { console.log(`Searching for ${term}`); },
};
// Add our commands to annyang
annyang.addCommands(commands);
// Start listening.
annyang.start();
}Running that page and saying hello should produce the alert, and saying search for anything should log the trailing words. The browser will ask permission to use the microphone the first time listening starts, which is a prompt your interface should expect rather than be surprised by.
If you prefer to import only what you use, the named form is equivalent.
import { addCommands, start, isSpeechRecognitionSupported } from 'annyang';A CommonJS require works, and a browser script tag build is published for pages with no build step at all. Covering all three module formats from one small package is the practical benefit of the version 3 rewrite.
Version 3 rewrote it in TypeScript without growing it
The release published on 2026-03-11 is described as a ground-up rewrite. The library moved to TypeScript and now ships its own type definitions, and it builds to standard modules, CommonJS and a browser script tag build from one source.
The detail that matters is what did not change. It is still two kilobytes and still has zero dependencies. A rewrite that adds type safety and three output formats while holding the size is a rewrite done with discipline, and size is the whole argument for a library in this category: nobody adds three hundred kilobytes to a page to support a voice shortcut.
Shipping its own types also removes a familiar annoyance, since type definitions maintained separately from a library drift from it. Here they are generated from the source.
The repository backs this up with the tooling you would want to see: a bundler configuration, a unit test setup, a separate manual test directory, a documentation generator configuration, linting and formatting configuration, and a demo directory. A manual test directory is a sensible admission, because automated tests cannot speak into a microphone, so some verification has to be done by a person.
The constraint is the browser, not the library
Everything limiting about annyang comes from underneath it, and a reader should be clear about where the boundary falls.
The library does not perform recognition. It hands that to the browser's own speech recognition interface, which means support, accuracy, language coverage and whether audio is processed locally or sent to a vendor's servers are all decided by the browser rather than by this code. The README does not document which browsers implement the interface, and the presence of a support-check function is the project's acknowledgement that some will not.
Practical consequences follow. Microphone access requires user permission and a secure context, so this will not work from a plain file or an insecure origin. Behaviour when recognition stops unexpectedly, after silence or a network interruption, is the kind of thing an application needs a policy for. And an interface built only around voice excludes anyone who cannot or will not speak to their computer, so voice should be an addition to a working interface rather than the only route through it.
None of this is a defect in a two kilobyte wrapper. It does mean that evaluating annyang means evaluating the browser capability it wraps, and that testing has to happen in the browsers your visitors actually use.
Calling the browser interface yourself is the alternative
The real alternative is skipping the library and using the browser's speech recognition interface directly.
The difference in approach is narrow and worth being precise about. Going direct gives you the raw transcript and complete control: your own matching logic, your own confidence thresholds, your own restart behaviour, and no dependency at all. For a single fixed phrase, that is genuinely less work than adding a package.
annyang earns its two kilobytes once you have more than a couple of commands, because the phrase matching and the capture syntax are the parts you would otherwise write and then maintain. The asterisk capture in particular is the piece most people implement badly the first time, since naive substring matching produces false positives on longer utterances.
For a GUI the author maintains a separate companion project that supplies the visual layer, showing listening status and offering the user sample commands, which is a real gap in the bare library: annyang gives you no interface, and a voice feature with no visible affordance is one nobody discovers. Treat that as a second decision rather than a bundled one.
MIT terms and what the repository signals
annyang is MIT licensed, which for a two kilobyte browser utility is the expected choice and raises nothing in a review.
The package sits at version 3.0.0, with the rewrite released on 2026-03-11 and the last push on 2026-08-05. A changelog and a contributing guide are present, documentation lives in the repository alongside a hosted tutorial and live demonstrations, and there is a frequently asked questions document, which for a library whose behaviour depends on browser support is the right place to put the awkward questions.
Upgrade cost is the one thing to plan for. Version 3 was a ground-up rewrite, so code written against version 2 should be checked rather than assumed, and the changelog is where that assessment starts. Against that, a library this size with no dependencies is about as cheap to hold as a dependency gets, and the absence of a dependency tree means nothing underneath it can change without you choosing to change it.
Editorial conclusion
annyang fits a site that wants a handful of spoken shortcuts alongside its existing interface, where two kilobytes and no dependencies matter more than controlling the recognition itself. Skip it when you need dictated prose rather than matched commands, or when one fixed phrase makes calling the browser interface directly the smaller job. Before committing, call the support check and test in the browsers your visitors actually use, because the library performs no recognition of its own and the README does not document which browsers implement the interface it wraps, and plan a visible affordance, since annyang ships no interface and an invisible voice feature goes unused.
Frequently asked questions
Is there a JavaScript library that can convert speech to text?
annyang is one option for the command case. It is a two kilobyte, dependency-free library that matches spoken phrases against commands you define and calls the matching function, using the browser's own speech recognition rather than performing recognition itself.
How do I capture a variable part of an annyang command?
Write the command key with an asterisk followed by a name, such as a search phrase ending in a starred term. Whatever the user says after the fixed words is passed to your function as an argument, so one command definition handles every value.
Which module formats does annyang 3 support?
The version 3 rewrite ships standard modules, CommonJS and a browser script tag build from one TypeScript source, along with its own type definitions. It remains two kilobytes with zero dependencies.
Does annyang work in every browser?
It depends on the browser implementing a speech recognition interface, which annyang wraps rather than replaces. The library exposes a support check function for exactly this reason, and your code should handle the unsupported case.
Community notes