refactor: extrai coordenação da conversa para VoiceSession
This commit is contained in:
17
README.md
17
README.md
@@ -25,7 +25,8 @@ A modular voice pipeline for streaming audio input, speech transcription, agent
|
||||
```mermaid
|
||||
flowchart TB
|
||||
C[Audio Client] <-->|WebSocket /ws/audio · JSON + binary PCM| G[Audio Gateway · FastAPI]
|
||||
G --> P[VoicePipeline]
|
||||
G --> U[VoiceSession · conversation lifecycle]
|
||||
U --> P[VoicePipeline]
|
||||
P --- S[SessionState · session and audio sequence]
|
||||
P --- T[TurnManager · semantic turn state]
|
||||
G --> STT[NVIDIA ASR · STT per turn]
|
||||
@@ -37,7 +38,7 @@ flowchart TB
|
||||
G -->|Streamed audio| C
|
||||
```
|
||||
|
||||
The **Audio Gateway** handles transport and protocol messages. **VoicePipeline** coordinates processing and task ownership. **SessionState** tracks session and audio sequence; **TurnManager** enforces turn transitions. A new STT adapter is created for each turn, while Agent and TTS adapters are created per session.
|
||||
The **Audio Gateway** handles transport, protocol validation, and application composition. **VoiceSession** coordinates STT, finalization, interruption, rollback, and provider cleanup. **VoicePipeline** retains processing, turn-state operations, and execution-task ownership. **SessionState** tracks session and audio sequence; **TurnManager** enforces turn transitions. A new STT adapter is created for each turn, while Agent and TTS adapters are created per session.
|
||||
|
||||
## Architecture Backbone & Abstraction Boundaries
|
||||
|
||||
@@ -57,6 +58,7 @@ The architecture separates five concerns:
|
||||
flowchart TB
|
||||
Client["Web Client / Audio Client"]
|
||||
Gateway["Audio Gateway<br/>FastAPI · WebSocket"]
|
||||
UseCase["VoiceSession<br/>Conversation Lifecycle"]
|
||||
Pipeline["VoicePipeline<br/>Orchestration & Streaming"]
|
||||
Session["SessionState<br/>Session Lifecycle"]
|
||||
Turns["TurnManager<br/>Semantic Turn Lifecycle"]
|
||||
@@ -83,7 +85,8 @@ flowchart TB
|
||||
end
|
||||
|
||||
Client <-->|"JSON Events + Binary PCM"| Gateway
|
||||
Gateway --> Pipeline
|
||||
Gateway --> UseCase
|
||||
UseCase --> Pipeline
|
||||
|
||||
Pipeline --- Session
|
||||
Pipeline --- Turns
|
||||
@@ -144,7 +147,9 @@ The primary configuration components are:
|
||||
| Dynamic provider loading | `providers.py` |
|
||||
| Session lifecycle | `domain/session.py` |
|
||||
| Semantic turn lifecycle | `turn_manager.py` |
|
||||
| Execution orchestration | `voice_pipeline.py` |
|
||||
| Conversation lifecycle | `application/voice_session.py` |
|
||||
| Application output events | `application/events.py` |
|
||||
| Processing and execution tasks | `voice_pipeline.py` |
|
||||
|
||||
### Streaming Execution Backbone
|
||||
|
||||
@@ -176,7 +181,8 @@ flowchart TB
|
||||
Output["WebSocket PCM Output"]
|
||||
|
||||
Input --> Gateway
|
||||
Gateway --> STT
|
||||
Gateway --> UseCase["VoiceSession"]
|
||||
UseCase --> STT
|
||||
STT --> Transcript
|
||||
Transcript --> Agent
|
||||
|
||||
@@ -381,6 +387,7 @@ The script reads `audios/chafik_normalize.wav` (16 kHz, mono, 16-bit PCM), sends
|
||||
config/ Environment YAML and provider catalog
|
||||
src/voice_assistant/
|
||||
audio_gateway/app/ WebSocket endpoint and protocol
|
||||
application/ VoiceSession and transport-independent events
|
||||
domain/ Session state and domain rules
|
||||
audio/ Canonical audio models
|
||||
stt/ STT contract, mock and NVIDIA adapter
|
||||
|
||||
Reference in New Issue
Block a user