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

@cloudflare/voice

v0.0.3

Published

Voice pipeline for Cloudflare Agents — STT, TTS, VAD, streaming, and SFU utilities

Downloads

2,828

Readme

@cloudflare/voice

Voice pipeline for Cloudflare Agents -- STT, TTS, VAD, streaming, and real-time audio over WebSocket.

Experimental. This API is under active development and will break between releases. Pin your version and expect to rewrite when upgrading.

Install

npm install @cloudflare/voice

Exports

| Export path | What it provides | | -------------------------- | ------------------------------------------------------------------------------------------------------- | | @cloudflare/voice | Server-side mixins (withVoice, withVoiceInput), provider types, Workers AI providers, SFU utilities | | @cloudflare/voice/react | React hooks (useVoiceAgent, useVoiceInput) | | @cloudflare/voice/client | Framework-agnostic VoiceClient class |

Server: full voice agent (withVoice)

Adds the complete voice pipeline: audio buffering, VAD, STT, LLM turn handling, streaming TTS, interruption, and conversation persistence.

import { Agent } from "agents";
import { withVoice, type VoiceTurnContext } from "@cloudflare/voice";

const VoiceAgent = withVoice(Agent);

export class MyAgent extends VoiceAgent<Env> {
  async onTurn(transcript: string, context: VoiceTurnContext) {
    // Return a string or AsyncIterable<string> (for streaming TTS)
    return "Hello! I heard you say: " + transcript;
  }
}

Provider properties

| Property | Type | Required | Description | | -------------- | ---------------------- | -------- | ------------------------------------------ | | stt | STTProvider | No | Batch speech-to-text (default: Workers AI) | | tts | TTSProvider | Yes | Text-to-speech (default: Workers AI) | | vad | VADProvider | No | Voice activity detection | | streamingStt | StreamingSTTProvider | No | Streaming STT for real-time transcripts |

Lifecycle hooks

| Method | Description | | -------------------------------- | ---------------------------------------------------------------------------------- | | onTurn(transcript, context) | Required. Handle a user utterance. Return string or AsyncIterable<string>. | | onCallStart(connection) | Called when a voice call begins. | | onCallEnd(connection) | Called when a voice call ends. | | onInterrupt(connection) | Called when user interrupts playback. | | beforeCallStart(connection) | Return false to reject a call. | | onMessage(connection, message) | Handle non-voice WebSocket messages (voice protocol is intercepted automatically). |

Pipeline hooks

| Method | Description | | ------------------------------------------ | ---------------------------------------------------- | | beforeTranscribe(audio, connection) | Process audio before STT. Return null to skip. | | afterTranscribe(transcript, connection) | Process transcript after STT. Return null to skip. | | beforeSynthesize(text, connection) | Process text before TTS. Return null to skip. | | afterSynthesize(audio, text, connection) | Process audio after TTS. Return null to skip. |

Convenience methods

  • speak(connection, text) -- synthesize and send audio to one connection
  • speakAll(text) -- synthesize and send audio to all connections
  • forceEndCall(connection) -- programmatically end a call
  • saveMessage(role, content) -- persist a message to conversation history
  • getConversationHistory() -- retrieve conversation history from SQLite

Server: voice input only (withVoiceInput)

STT-only mixin -- no TTS, no LLM. Use when you only need speech-to-text (e.g., dictation, transcription).

import { Server } from "partyserver";
import { withVoiceInput, WorkersAIFluxSTT } from "@cloudflare/voice";

const InputServer = withVoiceInput(Server);

export class VoiceInputAgent extends InputServer<Env> {
  streamingStt = new WorkersAIFluxSTT(this.env.AI);

  onTranscript(text: string, connection: Connection) {
    console.log("User said:", text);
  }
}

Client: React

import { useVoiceAgent } from "@cloudflare/voice/react";

function App() {
  const {
    status, // "idle" | "listening" | "thinking" | "speaking"
    transcript, // TranscriptMessage[]
    interimTranscript, // string | null (real-time partial transcript)
    metrics, // VoicePipelineMetrics | null
    audioLevel, // number (0-1)
    isMuted, // boolean
    connected, // boolean
    error, // string | null
    startCall, // () => Promise<void>
    endCall, // () => void
    toggleMute, // () => void
    sendText, // (text: string) => void
    sendJSON // (data: Record<string, unknown>) => void
  } = useVoiceAgent({ agent: "my-agent" });

  return <div>Status: {status}</div>;
}

For voice input only:

import { useVoiceInput } from "@cloudflare/voice/react";

const { transcript, interimTranscript, isListening, start, stop, clear } =
  useVoiceInput({ agent: "VoiceInputAgent" });

Client: vanilla JavaScript

import { VoiceClient } from "@cloudflare/voice/client";

const client = new VoiceClient({ agent: "my-agent" });

client.addEventListener("statuschange", () => console.log(client.status));
client.connect();
await client.startCall();

Workers AI providers (built-in)

All default providers use Workers AI bindings -- no API keys required:

| Class | Type | Workers AI model | | ------------------ | ------------- | --------------------------------- | | WorkersAISTT | Batch STT | @cf/deepgram/nova-3 | | WorkersAIFluxSTT | Streaming STT | @cf/deepgram/nova-3 (WebSocket) | | WorkersAITTS | TTS | @cf/deepgram/aura-1 | | WorkersAIVAD | VAD | @cf/pipecat-ai/smart-turn-v2 |

Third-party providers

| Package | What it provides | | ------------------------------ | ---------------------------------------- | | @cloudflare/voice-deepgram | Streaming STT (Deepgram Nova) | | @cloudflare/voice-elevenlabs | TTS (ElevenLabs) | | @cloudflare/voice-twilio | Telephony adapter (Twilio Media Streams) |

Related