Utterance

Constructor

import { Utterance } from "@utterance/core";

const detector = new Utterance(options);

Options

OptionTypeDefaultDescription
sensitivitynumber0.5Detection sensitivity (0–1). Higher = more sensitive to pauses
pauseTolerancenumber1500Max thinking pause duration in ms before triggering turnEnd
modelPathstringbundledCustom model path (ONNX)
sampleRatenumber16000Audio sample rate in Hz

Methods

MethodDescription
start()Begin listening (returns Promise<void>)
stop()Stop listening and release microphone
isListening()Returns current listening state (boolean)

Events

Register listeners with detector.on(event, callback) and remove them with detector.off(event, callback).

speechStart

Fired when the user starts speaking.

detector.on("speechStart", (event) => {
  event.timestamp; // number — Unix timestamp
});

pause

Fired when a thinking pause is detected (user likely not done).

detector.on("pause", (event) => {
  event.duration;   // number — pause duration in ms
  event.confidence; // number — 0 to 1
});

turnEnd

Fired when the user finishes speaking (safe to respond).

detector.on("turnEnd", (event) => {
  event.confidence; // number — 0 to 1
  event.duration;   // number — total speech duration in ms
});

interrupt

Fired when the user wants to interject (stop AI response).

detector.on("interrupt", (event) => {
  event.timestamp; // number — Unix timestamp
});

Types

All types are exported from @utterance/core:

import type {
  UtteranceOptions,
  UtteranceEvent,
  UtteranceEventMap,
  SpeechStartEvent,
  PauseEvent,
  TurnEndEvent,
  InterruptEvent,
  AudioFeatures,
  ClassificationResult,
  ClassificationLabel,
} from "@utterance/core";

On this page