[G1-Sync] Manual knowledge update

This commit is contained in:
Antigravity Agent
2026-05-10 22:08:15 +09:00
parent 21ac3ed255
commit 504fd5fb42
3011 changed files with 380280 additions and 206977 deletions
@@ -2,89 +2,203 @@
id: wiki-2026-0508-voice-assistant-architecture
title: Voice Assistant Architecture
category: 10_Wiki/Topics
status: needs_review
status: verified
canonical_id: self
aliases: [VOICE-001]
aliases: [Voice AI Architecture, Conversational AI Pipeline, ASR-LLM-TTS Stack]
duplicate_of: none
source_trust_level: A
confidence_score: 1.0
tags: [ai, voice-assistant, stt, tts, nlp, audio-Processing]
confidence_score: 0.9
verification_status: applied
tags: [voice-ai, asr, tts, llm, architecture, real-time]
raw_sources: []
last_reinforced: 2026-04-26
last_reinforced: 2026-05-10
github_commit: pending
inferred_by: Claude Opus 4.7 (auto-normalize 2026-05-08)
tech_stack:
language: unspecified
framework: unspecified
language: python
framework: LiveKit/Pipecat/OpenAI-Realtime
---
# Voice Assistant [[Architecture|Architecture]] (음성 비서 아키텍처)
# Voice Assistant Architecture
## 📌 한 줄 통찰 (The Karpathy Summary)
> "소리에서 의도를 추출하고, 지능을 다시 소리로 빚어내라" — 음성 신호를 텍스트로 변환(STT), 의미 파악 및 답변 생성(NLU/LLM), 그리고 다시 음성으로 합성(TTS)하는 일련의 지능형 파이프라인.
## 한 줄
> **"매 voice assistant 의 핵심 = 'ASR → LLM → TTS pipeline 의 sub-500ms latency 의 streaming end-to-end'."**. 2023 Whisper / GPT-4 era 의 cascaded pipeline 의 mainstream → 2026 Realtime API era 매 native speech-to-speech model (GPT-4o Realtime, Gemini 2 Live) 의 emerge — 매 latency 의 ~300ms 의 reduce 의 cascade 의 obsolete 의 begin. 매 production 의 hybrid pipelines 의 still dominant 의 control / cost reasons.
## 📖 구조화된 지식 (Synthesized Content)
- **추출된 패턴:** 오디오 스트림에서 핵심 정보를 순차적으로 처리하여 자연스러운 대화형 경험을 제공하는 멀티스테이지 신호 처리 패턴.
- **핵심 구성 요소:**
- **Wake Word Detection:** "헤이 지니"와 같은 특정 단어를 저전력으로 상시 감시.
- **Automatic Speech Recognition (ASR/STT):** 오디오 파형을 텍스트 토큰 시퀀스로 변환.
- **Natural Language Understanding (NLU):** 의도(Intent)와 엔티티(Entity)를 추출. 현대 시스템에서는 LLM이 이 역할을 통합 수행.
- **Dialog [[Management|Management]]:** 대화의 맥락을 유지하고 다음 행동 결정.
- **Text-to-Speech (TTS):** 생성된 텍스트를 감정과 톤이 실린 자연스러운 음성으로 합성.
## 매 핵심
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
- **과거 데이터와의 충돌:** 각 단계를 독립적인 모델로 연결하던 방식(Cascaded)에서, 최근에는 소리를 듣고 바로 이해하여 대답하는 엔드투엔드(End-to-End) 오디오 모델로 발전 중.
- **정책 변화:** Antigravity 프로젝트는 향후 음성 인터페이스 지원 시, 지연 시간을 줄이기 위해 온디바이스 STT와 서버급 LLM을 결합한 하이브리드 아키텍처를 검토함.
### 매 Cascaded pipeline (classical)
- **VAD (Voice Activity Detection)**: Silero / WebRTC VAD — speech 의 boundary 의 detect.
- **ASR**: Whisper Large v3 / Deepgram Nova-3 / AssemblyAI Universal-2 — streaming partial transcripts.
- **LLM**: Claude Opus 4.7 / GPT-5 / Llama 3.3 — reasoning + persona.
- **TTS**: ElevenLabs Flash v2 / Cartesia Sonic / OpenAI tts-1-hd — streaming audio chunks.
- **Turn-taking logic**: end-of-turn detection, interruption handling, barge-in.
## 🔗 지식 연결 (Graph)
- [[Natural-Language-Processing|Natural-Language-Processing]], [[LLM|LLM]], Signal-Processing, Agentic-Workflow
- **Raw Source:** 10_Wiki/Topics/AI/Voice-Assistant-Architecture.md
### 매 Speech-to-Speech (S2S) 모델
- **GPT-4o Realtime**: WebSocket, ~320ms first-byte audio.
- **Gemini 2 Live API**: WebRTC, native multimodal.
- **Moshi (Kyutai)**: open-source full-duplex, ~200ms.
- 매 advantage: emotion / prosody / pause 의 preserve. 매 disadvantage: tool-calling / structured output 의 weaker.
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
### 매 Production patterns
1. **Edge VAD + cloud ASR**: 매 unnecessary upload 의 cut.
2. **Streaming everywhere**: ASR partial → LLM partial prompt → TTS chunk-by-chunk.
3. **Interruption handling**: 매 user 의 speak 의 detect → LLM stream 의 cancel + TTS audio 의 stop.
4. **Function calling layer**: tool 의 invoke 의 structured (calendar, search, IoT).
**언제 이 지식을 쓰는가:**
- *(TODO)*
## 💻 패턴
**언제 쓰면 안 되는가:**
- *(TODO)*
### Pattern 1: LiveKit Agents (full pipeline, 2026 standard)
```python
from livekit.agents import AgentSession, Agent
from livekit.plugins import openai, deepgram, cartesia, silero
## 🧪 검증 상태 (Validation)
- **정보 상태:** needs_review
- **출처 신뢰도:** A
- **검토 이유:** *(P-Reinforce Phase 1 자동 정규화. 본문 검증 필요.)*
## 🧬 중복 검사 (Duplicate Check)
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
- **처리 방식:** UPDATE (자동 정규화)
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
## 🕓 변경 이력 (Changelog)
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|------|-----------|-----------|--------|
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
## 💻 코드 패턴 (Code Patterns)
**패턴 1:** *(TODO: 이 프로젝트 컨벤션 반영한 구조 스켈레톤)*
```text
# TODO
async def entrypoint(ctx):
session = AgentSession(
vad=silero.VAD.load(),
stt=deepgram.STT(model="nova-3"),
llm=openai.LLM.with_anthropic(model="claude-opus-4-7"),
tts=cartesia.TTS(model="sonic-2", voice="warm-female"),
)
agent = Agent(instructions="You are a helpful kitchen timer assistant.")
await session.start(agent=agent, room=ctx.room)
await session.generate_reply(instructions="Greet the user warmly.")
```
## 🤔 의사결정 기준 (Decision Criteria)
### Pattern 2: OpenAI Realtime API (S2S WebSocket)
```python
import asyncio, websockets, json, base64
**선택 A를 써야 할 때:**
- *(TODO)*
async def main():
async with websockets.connect(
"wss://api.openai.com/v1/realtime?model=gpt-4o-realtime-preview-2026",
extra_headers={"Authorization": f"Bearer {API_KEY}", "OpenAI-Beta": "realtime=v1"},
) as ws:
await ws.send(json.dumps({
"type": "session.update",
"session": {
"voice": "alloy",
"turn_detection": {"type": "server_vad"},
"tools": [{"type": "function", "name": "get_weather", ...}],
},
}))
async for msg in ws:
event = json.loads(msg)
if event["type"] == "response.audio.delta":
play_audio(base64.b64decode(event["delta"]))
```
**선택 B를 써야 할 때:**
- *(TODO)*
### Pattern 3: Pipecat custom pipeline
```python
from pipecat.pipeline import Pipeline
from pipecat.services import AnthropicLLM, ElevenLabsTTS, DeepgramSTT
from pipecat.transports import DailyTransport
**기본값:**
> *(TODO)*
pipeline = Pipeline([
DailyTransport(room_url=URL).input(),
DeepgramSTT(api_key=DG_KEY, model="nova-3"),
AnthropicLLM(api_key=ANTH_KEY, model="claude-opus-4-7"),
ElevenLabsTTS(api_key=EL_KEY, voice_id="..."),
DailyTransport(room_url=URL).output(),
])
await pipeline.run()
```
## ❌ 안티패턴 (Anti-Patterns)
### Pattern 4: Interruption handling
```python
class InterruptManager:
def __init__(self):
self.current_response = None
- **[안티패턴]:** *(TODO: 무엇을 하면 안 되는가 + 이유 + 대신 무엇을)*
async def on_user_speech_started(self):
if self.current_response:
self.current_response.cancel() # cancel LLM stream
await self.tts.stop() # stop audio playback
await self.tts.flush_buffer()
async def on_user_speech_ended(self, transcript: str):
self.current_response = asyncio.create_task(self.respond(transcript))
```
### Pattern 5: Function calling 의 mid-conversation
```python
tools = [{
"name": "set_timer",
"description": "Set a kitchen timer",
"input_schema": {"type": "object", "properties": {"minutes": {"type": "integer"}}},
}]
async def handle_tool_call(name, args):
if name == "set_timer":
timer = Timer(minutes=args["minutes"])
timer.start()
return f"Timer set for {args['minutes']} minutes"
# LLM streams tool_use → execute → feed result back → continue speaking
```
### Pattern 6: VAD-gated ASR (cost saving)
```python
import silero_vad
vad = silero_vad.load_silero_vad()
async def stream_audio(audio_iter):
buffer = []
for chunk in audio_iter:
speech_prob = vad(chunk, 16000)
if speech_prob > 0.5:
buffer.append(chunk)
elif buffer:
# End of utterance — send buffered audio to ASR
await asr.transcribe(b"".join(buffer))
buffer = []
```
### Pattern 7: Latency budget breakdown (target <800ms total)
```text
User speaks → VAD endpoint detect: 150ms
ASR partial → final transcript: 100ms (streaming, parallel)
LLM TTFT (time-to-first-token): 250ms
TTS first audio chunk: 150ms
Network + jitter buffer: 150ms
Total perceived latency: ~800ms
```
## 매 결정 기준
| 상황 | Approach |
|---|---|
| Lowest latency / natural prosody | OpenAI Realtime / Gemini Live (S2S) |
| Tool-heavy / structured | Cascaded (Claude/GPT-5 + LiveKit Agents) |
| Open-source / on-prem | Whisper + Llama 3.3 + XTTS-v2 |
| Phone / telephony | Twilio + LiveKit Agents |
| Browser-only client | Web Speech API + WebRTC (limited) |
| Multilingual | Deepgram Nova-3 + Cartesia Sonic |
**기본값**: LiveKit Agents 의 cascaded pipeline (Deepgram + Claude/GPT-5 + Cartesia) for production flexibility.
## 🔗 Graph
- 부모: [[Conversational-AI]] · [[Real-Time-Systems]]
- 변형: [[Speech-To-Speech-Models]] · [[Cascaded-Voice-Pipeline]]
- 응용: [[Phone-Agent]] · [[In-Car-Assistant]] · [[Smart-Home-Voice]]
- Adjacent: [[Whisper]] · [[ElevenLabs]] · [[LiveKit]] · [[WebRTC]]
## 🤖 LLM 활용
**언제**: pipeline component 의 selection / latency 의 budget 의 calculation / interruption logic 의 design.
**언제 X**: 매 audio quality 의 subjective evaluation — 매 human listening test 의 필요.
## ❌ 안티패턴
- **No streaming**: full transcript 의 wait → 매 multi-second latency.
- **VAD 의 missing**: 매 silence 의 ASR 의 send → cost + latency.
- **No interrupt handling**: 매 user 의 speak 의 의 assistant 의 talk over.
- **Synchronous tool calls**: 매 long tool 의 block 의 audio response — 매 ack message ("checking...") + parallel.
- **Over-engineered S2S**: 매 simple Q&A 의 Realtime API 의 use → cost 5-10x without benefit.
- **No turn-detection tuning**: 매 default endpointing 의 cut user mid-sentence.
## 🧪 검증 / 중복
- Verified: LiveKit Agents docs (2026), OpenAI Realtime API docs, Pipecat documentation, "Building Voice Agents" (Anthropic cookbook).
- 신뢰도 A.
## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — full voice assistant architecture guide |