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

@caleblawson/voice-openai-realtime

v0.10.2

Published

Mastra OpenAI Realtime API integration

Readme

@mastra/voice-openai-realtime

OpenAI Realtime Voice integration for Mastra, providing real-time voice interaction capabilities using OpenAI's WebSocket-based API. This integration enables seamless voice conversations with real-time speech to speech capabilities.

Installation

npm install @mastra/voice-openai-realtime

Configuration

The module requires an OpenAI API key, which can be provided through environment variables or directly in the configuration:

OPENAI_API_KEY=your_api_key

Usage

import { OpenAIRealtimeVoice } from '@mastra/voice-openai-realtime';
import { getMicrophoneStream } from '@mastra/node-audio';

// Create a voice instance with default configuration
const voice = new OpenAIRealtimeVoice();

// Create a voice instance with configuration
const voice = new OpenAIRealtimeVoice({
  apiKey: 'your-api-key', // Optional, can use OPENAI_API_KEY env var
  model: 'gpt-4o-mini-realtime', // Optional, uses latest model by default
});

voice.updateSession({
  turn_detection: {
    type: 'server_vad',
    threshold: 0.5,
    silence_duration_ms: 1000,
  },
});

// Connect to the realtime service
await voice.open();

// Audio data from voice provider
voice.on('speaking', (audioData: Int16Array) => {
  // Handle audio data
});

// Text data from voice provider
voice.on('writing', (text: string) => {
  // Handle transcribed text
});

// Error from voice provider
voice.on('error', (error: Error) => {
  console.error('Voice error:', error);
});

// Generate speech
await voice.speak('Hello from Mastra!', {
  speaker: 'echo', // Optional: override default speaker
});

// Listen to audio input
await voice.listen(audioData);

// Process audio input
const microphoneStream = getMicrophoneStream();
await voice.send(microphoneStream);

// Clean up
voice.close();

Features

  • Real-time voice interactions via WebSocket
  • Seamless speech to speech
  • Voice activity detection (VAD)
  • Multiple voice options
  • Event-based audio streaming
  • Tool integration support

Voice Options

Available voices include:

  • alloy (Neutral)
  • ash (Balanced)
  • echo (Warm)
  • shimmer (Clear)
  • coral (Expressive)
  • sage (Professional)
  • ballad (Melodic)
  • verse (Dynamic)

Events

The voice instance emits several events:

  • speaking: Emitted while generating speech, provides Int16Array audio data
  • writing: Emitted when speech is transcribed to text
  • error: Emitted when an error occurs

You can also listen to OpenAI Realtime sdk utility events by prefixing with 'openAIRealtime:', such as:

  • openAIRealtime:conversation.item.completed
  • openAIRealtime:conversation.updated

Voice Activity Detection

The realtime voice integration includes server-side VAD (Voice Activity Detection) with configurable parameters:

voice.updateConfig({
  voice: 'echo',
  turn_detection: {
    type: 'server_vad',
    threshold: 0.5, // Speech detection sensitivity
    silence_duration_ms: 1000, // Wait time before ending turn
    prefix_padding_ms: 1000, // Audio padding before speech
  },
});

Tool Integration

You can add tools to the voice instance with tools that extend its capabilities:

export const menuTool = createTool({
  id: 'menuTool',
  description: 'Get menu items',
  inputSchema: z
    .object({
      query: z.string(),
    })
    .required(),
  execute: async ({ context }) => {
    // Implement menu search functionality
  },
});

voice.addTools(menuTool);

API Reference

For detailed API documentation, refer to the JSDoc comments in the source code or generate documentation using TypeDoc.