返回內容列表

Push-to-Talk

按住按鈕才啓用麥克風,明確控制語音輪次。

TypeScript進階Therealratoshen
GitHub

實踐教程

本教程目錄

Push-to-Talk Voice Agent

Copyable prompt for coding agents

Build and run the Agora Conversational AI push-to-talk recipe in this repo. Read AGENTS.md and docs/ai/RECIPE.md fully. Copy .env.example to .env.local and fill Agora + LLM + TTS credentials. Run npm install --legacy-peer-deps && npm run dev. Open localhost:3000, start a conversation, and verify the agent only hears you while Push-to-Talk is engaged (hold or toggle). Do not remove the mic publish gate in lib/ptt.ts.

What you build

A browser ConvoAI client where microphone uplink is gated by push-to-talk (hold-to-talk or latch toggle). Use this in noisy rooms or when deliberate turns beat full-duplex barge-in.

Prerequisites

  • Node.js 20+
  • Agora App ID + App Certificate
  • LLM API key + TTS vendor credentials (see .env.example)

Run

bash
cp .env.example .env.local
npm install --legacy-peer-deps
npm run dev

Open http://localhost:3000 → start conversation.

Verification

  1. Join/start agent with PTT idle — speaking should not elicit an agent reply.
  2. Hold (or latch) Push-to-Talk, speak a short question — agent should answer.
  3. Release PTT — further speech should not be heard by the agent.
  4. npm test passes.

Non-goals

  • SIP / phone calling
  • Multi-agent handoff (see Agora agent-handoff recipe instead)
  • Custom LLM gateway unless required by your starter