M5 Update and Web Voice Agent using Terp AI.
This commit is contained in:
+20
-9
@@ -26,11 +26,14 @@ This directory contains the FastAPI backend for the AI Voice Agent, facilitating
|
||||
|
||||
### Configuration
|
||||
|
||||
Update the `.env` file in this directory with your ElevenLabs credentials:
|
||||
Update the `.env` file in this directory with your credentials:
|
||||
|
||||
```ini
|
||||
ELEVENLABS_API_KEY=your_elevenlabs_api_key_here
|
||||
ELEVENLABS_API_KEY=sk_...
|
||||
ELEVENLABS_VOICE_ID=JBFqnCBsd6RMkjVDRZzb
|
||||
TERP_AI_BEARER_TOKEN=eyJhbGciOiJSUz...
|
||||
TERP_AI_CONVERSATION_ID=37fa27cc-542a-c8a8-9c31-9d1954fdc1d2
|
||||
MONGODB_URI=mongodb+srv://...
|
||||
```
|
||||
|
||||
## Running the Server
|
||||
@@ -60,12 +63,18 @@ This is the primary WebSocket endpoint used by the M5GO device for real-time voi
|
||||
}
|
||||
```
|
||||
4. **Processing (Server):** Upon receiving the `stop_listening` event, the server executes the AI pipeline:
|
||||
- Transcribes the accumulated PCM audio using `faster-whisper`.
|
||||
- Sends the transcribed text to the Terp AI conversational endpoint and waits for the full response.
|
||||
- Sends the Terp AI response text to ElevenLabs TTS.
|
||||
- Converts the received TTS audio to 16-bit 16kHz Mono PCM.
|
||||
5. **Streaming Response (Server -> Client):** The server sends the converted PCM audio back to the client as binary frames.
|
||||
6. **End of Response (Server -> Client):** The server sends an empty binary frame (`b""`) to signal that playback is complete.
|
||||
- Transcribes the accumulated Int16 PCM audio organically using `faster-whisper`.
|
||||
- Injects a MongoDB aggregate map of the latest 24hr Campus Location noise levels seamlessly into the LLM system prompt.
|
||||
- Sends the transcribed text & location context to the Terp AI conversational endpoint and waits for the full response.
|
||||
- Streams the Terp AI response text directly to ElevenLabs TTS and demands `pcm_16000` via URL flags natively!
|
||||
5. **TTS Endpoint Notification**: The server saves the TTS audio buffer and pushes a JSON:
|
||||
```json
|
||||
{
|
||||
"event": "tts_ready",
|
||||
"size": 105000
|
||||
}
|
||||
```
|
||||
6. **Audio Callback**: Client queries `GET /api/tts-audio` to play the binary wav response.
|
||||
|
||||
## REST Endpoints
|
||||
|
||||
@@ -126,7 +135,9 @@ Returns a list of all recorded study room data from the last 24 hours, sorted by
|
||||
|
||||
## Client Integration Notes
|
||||
|
||||
For the ESP32/M5GO client (`m5go/main.py`), ensure you update the `WS_URL` variable to point to the correct local IP address of the machine running this backend server.
|
||||
For the ESP32/M5GO hardware client (`m5go/main.py`), ensure you update the `WS_URL` variable to point to the correct internal server IP.
|
||||
|
||||
For the Web Frontend (`VoiceButton.svelte`), it uses standard Web Audio API's `ScriptProcessorNode` to bridge the Float32 arrays strictly into 16-Bit Mono over a dynamic WebSocket tunnel automatically.
|
||||
|
||||
```python
|
||||
# In m5go/main.py
|
||||
|
||||
Reference in New Issue
Block a user