0
Fork 0
mirror of https://github.com/mastra-ai/mastra.git synced 2026-11-17 08:44:46 +00:00
mastra/voice/xai-realtime-api
History 2026-11-12 21:12:29 +00:00
..
src refactor(lint): remove redundant returns while preserving exits (#28448) 2026-10-26 21:03:00 +01:00
CHANGELOG.md chore: version - exit prerelease mode 2026-11-12 21:12:29 +00:00
lint-staged.config.js refactor(lint): replace ESLint with type-aware oxlint (#27476) 2026-10-18 10:38:35 -07:00
package.json chore: version - exit prerelease mode 2026-11-12 21:12:29 +00:00
README.md chore(*): Update/unify/add READMEs (#22858) 2026-09-02 14:36:59 +02:00
tsconfig.build.json feat(voice): add xAI realtime provider (#16507) 2026-05-14 10:51:35 -04:00
tsconfig.json chore: migrate package builds to tsdown (#19829) 2026-07-28 12:32:21 +02:00
tsdown.config.ts chore: migrate package builds to tsdown (#19829) 2026-07-28 12:32:21 +02:00
vitest.config.ts feat(voice): add xAI realtime provider (#16507) 2026-05-14 10:51:35 -04:00

@mastra/voice-xai-realtime

@mastra/voice-xai-realtime connects Mastra agents to xAI's Grok Voice Agent WebSocket API for low-latency, bidirectional text and audio conversations. Use it when an agent needs live speech, server-side turn detection, interruption handling, and realtime transcripts through a single voice provider.

Installation

npm install @mastra/voice-xai-realtime

Usage

Set XAI_API_KEY. The Node.js microphone and speaker example also uses the separately published @mastra/node-audio package.

import { Agent } from '@mastra/core/agent';
import { getMicrophoneStream, playAudio } from '@mastra/node-audio';
import { XAIRealtimeVoice } from '@mastra/voice-xai-realtime';

const voice = new XAIRealtimeVoice({
  apiKey: process.env.XAI_API_KEY,
  model: 'grok-voice-think-fast-1.0',
  speaker: 'eve',
  instructions: 'You are a concise voice assistant.',
  turnDetection: { type: 'server_vad' },
});

const agent = new Agent({
  id: 'voice-agent',
  name: 'Voice Agent',
  instructions: 'You are a helpful voice assistant.',
  model: 'xai/grok-4.3',
  voice,
});

await agent.voice.connect();

agent.voice.on('speaker', audioStream => {
  playAudio(audioStream);
});

agent.voice.on('writing', ({ text, role }) => {
  console.log(`${role}: ${text}`);
});

await agent.voice.speak('How can I help you today?');

const microphoneStream = getMicrophoneStream();
await agent.voice.send(microphoneStream);

Documentation

Changelog

See the package changelog for version history and release notes.

Support

We have an open community Discord. Come and say hello and let us know if you have any questions or need any help getting things running.