add-voice
它能做什么
让智能体为现有应用添加实时语音对话功能,麦克风发送语音,语音回复返回给用户。适合开发语音助手的开发者。
适用场景
- ✓当你希望用户能够通过语音与 AI 实时对话的时候。
- ✓当你的应用使用了独立的语音转文字、语言模型和文字转语音步骤,而这些步骤可以合并为一个语音循环的时候。
- ✓当你希望在应用中提供一个安全认证的语音模式按钮的时候。
技能链接
https://github.com/cursor/plugins/blob/main/grok-voice/skills/add-voice/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请为我们的应用添加语音模式,让用户可以与智能体对话,并实时听到它的回复。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会梳理你的应用,通过你的服务器或临时令牌设置安全访问,并将麦克风连接到一个实时语音连接,实现音频的输入和输出。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Add Voice
Add Grok Speech to Speech to an existing app. Run on /add-voice, typed Voice Mode, or clear “add Grok voice” intent.
Goal
Working duplex path: user-app mic in, audio out, wss://api.x.ai/v1/realtime?model=grok-voice-latest, safe auth. Cursor has no native mic; wire the app (or a sample client), not the IDE.
Protocol first
Language-agnostic event loop. TypeScript samples default. Short Python twins only where the client API differs (e.g. ws vs websockets).
Docs
- https://docs.x.ai/developers/model-capabilities/audio/speech-to-speech
- https://docs.x.ai/developers/model-capabilities/audio/ephemeral-tokens
- Pricing (cite docs only): https://docs.x.ai/developers/pricing (~$0.08/min STS + $0.004/text item; max session 120 min)
Steps
Map the app
- Stack: none, OpenAI Realtime, STT→LLM→TTS cascade, TTS/STT only.
- Client: web / Node / iOS / Android / server.
- If a cascade or OpenAI Realtime exists: replace it with the single duplex loop below (URL, model, voice, event diffs); keep standalone
/v1/sttor/v1/ttsonly if the product still needs one-shot listen or speak outside the agent.
Auth
- Server: Bearer
XAI_API_KEY. - Browser/mobile: backend
POST https://api.x.ai/v1/realtime/client_secrets, client uses ephemeral token (Bearer or browsersec-websocket-protocol:xai-client-secret.<token>). - Never put a long-lived key in client bundles. Do not paste keys in chat.
- Server: Bearer
Connect + session
- URL:
wss://api.x.ai/v1/realtime?model=grok-voice-latest - On open:
session.updatewithvoice(defaulteve),instructions,turn_detection: { type: "server_vad" }(ornullfor push-to-talk), PCM 24 kHz unless the app already standardizes elsewhere. - Set
audio.input.transcription.model: "grok-transcribe"or no user transcript arrives (conversation.item.input_audio_transcription.updatedis cumulative, not a delta). - Tools if needed:
web_search,x_search,file_search,mcp, customfunction.
- URL:
Audio I/O (app-side)
- One
AudioContextper session for capture and playback, created inside the user gesture (autoplay policy). Ask for 24 kHz; if the browser gives another rate, resample before sending. - Mic → AudioWorklet in ~100 ms chunks →
input_audio_buffer.append(or binary transport). Start WS and mic in parallel; buffer early audio, flush on open. - Play
response.output_audio.deltaimmediately; schedule with a ~150 ms lead so chunks butt together. Oninput_audio_buffer.speech_started, stop everything queued (barge-in). - Transcript rows: create the user row on
input_audio_buffer.committed(item_id), fill it on…transcription.updated; assistant text fromresponse.output_audio_transcript.delta/.done, close the turn onresponse.done. - On function tools:
function_call_output, finish playback, thenresponse.create.
- One
Composer UI convention
- One primary button, right side of the composer. Empty composer → waveform icon (stroked, e.g. Phosphor
WaveformIcon weight="bold"; never thefillweight, which renders as a blob at 16 px), starts voice mode. Any text present → classic send arrow; in voice mode that text goes into the live session (conversation.item.create+response.create). Text reply streaming → stop square. - While voice is live the same button shows an animated waveform (4 bars, ~3 px wide, 2 px gap, ~16 px tall, min scale 0.4 so they stay legible in a 28 px button) and ends the session on click. Phase drives the animation: listening slow, speaking fast, connecting/thinking slower and slightly dimmed (opacity ≥ 0.75). Honor
prefers-reduced-motion. No X button, no pulsing ring. - Status lives in the composer, not around it: the placeholder reads
Connecting…/Listening…/Thinking…/Speaking…, plus ansr-onlyrole="status". No separate status row. - The microphone icon is reserved for dictation (
/add-dictation). Never use it for voice mode.
- One primary button, right side of the composer. Empty composer → waveform icon (stroked, e.g. Phosphor
TS skeleton (default)
const url = "wss://api.x.ai/v1/realtime?model=grok-voice-latest";
// Node: pass Authorization header. Browser: use xai-client-secret.<token> protocol.
const ws = new WebSocket(url /* , { headers: { Authorization: `Bearer ${token}` } } */);
ws.addEventListener("open", () => {
ws.send(JSON.stringify({
type: "session.update",
session: {
voice: "eve",
instructions: "You are a helpful voice agent.",
常见问题
API 密钥安全吗?
安全。浏览器和移动应用使用你后端提供的临时令牌,而不是主密钥。
它会替换旧的设置吗?
如果你的应用使用了独立的语音转文字、语言模型和语音链路,该技能可以用一个语音循环替换它。
麦克风由谁处理?
由你的应用处理,因为编码工具本身没有麦克风。
详情
作者的原始描述
Use when the user runs /add-voice, types Voice Mode, or asks to add Grok realtime voice to an app, including replacing an STT-LLM-TTS cascade or OpenAI Realtime. Wire speech-to-speech, safe auth, and app mic. Composer: waveform button, mic icon reserved for dictation. For mic-to-text only use /add-dictation; to speak text replies use /add-read-aloud. To add debug logging and fix from logs use /debug-voice.
repo: cursor/plugins
热度
- GitHub 星标
- 15k
- 排名
- #10952
- 许可证
- —
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
advisor
15k如果你开启该功能,让你的智能体在关键节点咨询一个更强的第二模型,例如在重大决定之前,或在错误上卡住时。
check-agent-compatibility
15k全面检查 AI 编程智能体能否启动、验证和记录某个代码仓库,并返回一个兼容性评分以及主要问题。
cli-for-agents
15k教你的智能体设计或审查命令行工具,使 AI 智能体无需提示即可运行,并提供清晰的帮助文字和示例。
continual-learning
15k通过把回顾过往对话的工作交给专门的记忆更新程序,使你的 AGENTS.md 笔记保持最新。