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

@cutos/speech-synthesis

v4.0.0

Published

CUTOS 4.0 browser-side Web Speech API text-to-speech SDK.

Downloads

154

Readme

@cutos/speech-synthesis

Browser-side text-to-speech SDK for CUTOS 4.0 LWA applications. It wraps the standard Web Speech API (window.speechSynthesis) and uses voices exposed by the current browser or Windows WebView runtime.

This is an npm SDK, not a CUTOS Capability/Provider:

  • no Device Provider or .drv package;
  • no Gateway service;
  • no CUTOS Server request; and
  • no required network connection.

For offline speech, install a compatible local Windows voice and prefer a voice returned with localService: true.

Installation

npm install @cutos/speech-synthesis

The package has no runtime npm dependencies.

Quick Start

Call speak() from a user action, such as a button click. Some Chromium and WebView runtimes block automatically started speech.

import { SpeechSynthesizer } from '@cutos/speech-synthesis'

if (!SpeechSynthesizer.isSupported()) {
  throw new Error('This CUTOS Runtime does not expose the Web Speech API.')
}

const speech = new SpeechSynthesizer()
const voices = await speech.ready()
const voice = voices.find(item => item.localService && item.lang.toLowerCase().startsWith('zh'))

await speech.speak({
  text: '欢迎使用 CUTOS',
  lang: 'zh-CN',
  voiceURI: voice?.voiceURI,
  rate: 1,
  pitch: 1,
  volume: 1
})

API

SpeechSynthesizer.isSupported()

Returns true only when both speechSynthesis and SpeechSynthesisUtterance are exposed by the current runtime. Constructing SpeechSynthesizer when unsupported throws SpeechSynthesisUnavailableError.

new SpeechSynthesizer()

Creates a wrapper around the browser-global speech synthesis queue. The browser owns that queue, so use one application-level instance rather than creating multiple competing instances.

ready(timeoutMs?: number)

Returns Promise<SpeechVoiceInfo[]>. Voice enumeration is asynchronous in many Windows WebView runtimes; this method waits for voiceschanged for up to 1500 ms by default, then returns the currently available voice list. It does not guarantee that a voice is installed.

getVoices(query?: VoiceQuery)

Returns serializable metadata for the currently available voices.

const allVoices = speech.getVoices()
const localChineseVoices = speech.getVoices({ lang: 'zh-CN', localOnly: true })
interface VoiceQuery {
  lang?: string       // prefix match, for example "zh" or "en-US"
  localOnly?: boolean // only voices whose runtime reports localService: true
}

interface SpeechVoiceInfo {
  name: string
  lang: string
  voiceURI: string
  localService: boolean
  default: boolean
}

localService is supplied by the underlying runtime. Treat it as a useful preference, not an absolute guarantee about how a voice vendor implements synthesis.

speak(options)

Queues one utterance and returns Promise<SpeechResult> when it completes. Text is trimmed and cannot be empty. If voiceURI is supplied, it must identify a voice returned by getVoices().

const result = await speech.speak({
  text: 'CUTOS is ready.',
  lang: 'en-US',
  voiceURI: selectedVoice.voiceURI,
  rate: 1,
  pitch: 1,
  volume: 0.9
})

console.log(result.elapsedTime, result.charIndex)
interface SpeakOptions {
  text: string
  lang?: string
  voiceURI?: string
  rate?: number   // 0.1–10, default 1
  pitch?: number  // 0–2, default 1
  volume?: number // 0–1, default 1
}

interface SpeechResult {
  status: 'completed'
  elapsedTime: number // seconds reported by the browser when available
  charIndex: number
}

Calling speak() while another SDK utterance is active first cancels that utterance. The earlier promise rejects with SPEECH_CANCELLED; the new utterance then starts.

Playback Controls And State

speech.pause()
speech.resume()
speech.cancel()

const state = speech.getState()
// { supported: true, speaking, pending, paused }

cancel() stops the active SDK utterance and rejects its pending speak() promise with SPEECH_CANCELLED.

Events

const off = speech.on('boundary', event => {
  console.log(event.charIndex, event.elapsedTime)
})

off()
// or: speech.off('boundary')

Supported event names are start, end, pause, resume, boundary, error, and cancel.

interface SpeechEvent {
  type: SpeechEventType
  timestamp: number
  charIndex?: number
  elapsedTime?: number
  error?: string
  text?: string
}

Errors

All operational SDK errors extend SpeechSynthesisError and expose a stable code.

| Code | Meaning | | --- | --- | | EMPTY_TEXT | speak() received empty or whitespace-only text. | | VOICE_NOT_FOUND | voiceURI is not present in the current voice list. | | SPEECH_CANCELLED | cancel() or a later speak() cancelled the active utterance. | | SPEECH_ERROR or browser value | The Web Speech API reported a synthesis error. |

SpeechSynthesisUnavailableError is thrown when the runtime has no Web Speech API implementation.

Offline Windows Requirements

  • The LWA must run in a Windows CUTOS Runtime whose WebView exposes the Web Speech API.
  • Windows must have a language speech voice installed and visible to that WebView.
  • The SDK never uploads text or downloads voice data.
  • Do not select voices named Online when offline operation is a requirement; prefer a listed local voice and validate it on the target Runtime.

Use demo-speech-synthesis to inspect the actual voice list and validate speech on a target device before release.