11
ProAndroidDev
作者:Sahil Memon
發布:05-13 13:37
Engineering Real-Time Conversational Voice AI on Android
Most implementations stop at the pipeline. Conversation starts after.
重點摘要
Use a five-state machine to coordinate listening, thinking, speaking, and errors
Stream STT, LLM, and TTS in real time with cancellation-aware coroutines
Handle barge-in, stale transcripts, and device audio quirks with guards and shared audio capture
This article explains how to build a real-time conversational voice AI on Android that works in actual back-and-forth dialogue, not just demos. It frames the system as a loop of listening, thinking, and speaking, then shows how a five-state machine prevents race conditions across STT, LLM, TTS, and barge-in handling. The author covers streaming microphone audio to STT, pre-warming WebSocket connections, streaming LLM tokens through cancellation-aware flows, and flushing sentence-level TTS as soon as boundaries are detected. It also details practical Android issues such as echo cancellation, session-ID guards, one shared AudioRecord for the whole session, and on-device VAD for interrupt detection.
在 Android 上工程化实时对话式语音 AI
大多数实现只停留在流水线,真正的对话是在流水线之后才开始。
重點摘要
用五状态机统一协调监听、思考、说话和错误状态
通过可取消协程串流 STT、LLM 和 TTS
用会话 guard、共享录音和本地 VAD 处理插话与设备问题
本文介绍如何在 Android 上构建真正可进行来回对话的实时语音 AI,而不是只适合演示的“录音—转写—LLM—TTS”流水线。作者把系统抽象为“监听、思考、说话”的循环,并用五状态机避免 STT、LLM、TTS 和插话逻辑之间的竞态。文章进一步讲解了流式麦克风输入、WebSocket 预连接、基于可取消 Flow 的 LLM 输出,以及按句切分后立即触发 TTS 播放。最后还讨论了回声消除、过期会话结果拦截、单一 AudioRecord 贯穿整个会话,以及使用本地 VAD 进行 barge-in 检测等关键实现细节。
在 Android 上打造即時對話式語音 AI
多數實作只做到流程,真正的對話是在流程之後才開始。
重點摘要
以五狀態機協調聆聽、思考、發話與錯誤處理
用可取消的協程串流 STT、LLM 與 TTS
透過 session guard、共享錄音與 VAD 解決插話與裝置相容性問題
本文說明如何在 Android 上打造真正可對話的即時語音 AI,而不只是錄音、轉寫、送入 LLM 再用 TTS 朗讀的示範版。作者先建立「聆聽、思考、發話」的循環模型,並用五狀態機避免 STT、LLM、TTS 與插話處理之間的競態條件。文中也涵蓋串流式麥克風輸入、WebSocket 預熱、以可取消流程串接 LLM token、以及依句子邊界即時觸發 TTS。最後補充 Android 上常見的回音消除、session 過期結果、單一 AudioRecord 與裝置端 VAD 等實作細節。