Skip to content

Commit bbddc9d

Browse files
author
recipes-bot
committed
feat(python): voice-agents v1 — custom-tts
1 parent e69e99d commit bbddc9d

3 files changed

Lines changed: 107 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Custom TTS (Voice Agents v1)
2+
3+
Configure a custom text-to-speech voice for the voice agent's audio output.
4+
5+
## What it does
6+
7+
This recipe demonstrates how to customize the Text-to-Speech (TTS) configuration in a Deepgram voice agent. It shows how to select different voice models to change the character and tone of the agent's spoken responses, creating distinct voice personalities for different use cases.
8+
9+
## Key parameters
10+
11+
| Parameter | Value | Description |
12+
|-----------|-------|-------------|
13+
| `speak.provider.model` | `"aura-2-arcas-en"` | Custom voice model (male voice character) |
14+
| `speak.provider.type` | `"deepgram"` | TTS provider (Deepgram Aura voices) |
15+
16+
## Example output
17+
18+
```
19+
Configuring Voice Agent with Custom TTS Voice...
20+
Voice agent configured with custom TTS voice!
21+
Listen Model: nova-3 (Deepgram)
22+
Think Model: gpt-4o-mini (OpenAI)
23+
Speak Model: aura-2-arcas-en (Deepgram) - Male Voice
24+
Agent will respond with a distinct male voice character.
25+
```
26+
27+
## Prerequisites
28+
29+
- Python 3.10+
30+
- Set `DEEPGRAM_API_KEY` environment variable
31+
- Install: `pip install -r recipes/python/requirements.txt`
32+
33+
## Run
34+
35+
```bash
36+
python example.py
37+
```
38+
39+
## Test
40+
41+
```bash
42+
pytest example_test.py -v
43+
```
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""Demonstrates selecting a custom TTS voice for the voice agent."""
2+
3+
from deepgram import DeepgramClient
4+
from deepgram.agent.v1.types import (
5+
AgentV1Settings, AgentV1SettingsAgent, AgentV1SettingsAgentListen,
6+
AgentV1SettingsAgentListenProvider_V1, AgentV1SettingsAudio,
7+
AgentV1SettingsAudioInput,
8+
)
9+
from deepgram.types.think_settings_v1 import ThinkSettingsV1
10+
from deepgram.types.think_settings_v1provider import ThinkSettingsV1Provider_OpenAi
11+
from deepgram.types.speak_settings_v1 import SpeakSettingsV1
12+
from deepgram.types.speak_settings_v1provider import SpeakSettingsV1Provider_Deepgram
13+
14+
15+
def main():
16+
client = DeepgramClient() # reads DEEPGRAM_API_KEY from environment
17+
18+
with client.agent.v1.connect() as agent:
19+
settings = AgentV1Settings(
20+
audio=AgentV1SettingsAudio(
21+
input=AgentV1SettingsAudioInput(encoding="linear16", sample_rate=24000),
22+
),
23+
agent=AgentV1SettingsAgent(
24+
listen=AgentV1SettingsAgentListen(
25+
provider=AgentV1SettingsAgentListenProvider_V1(type="deepgram", model="nova-3"),
26+
),
27+
think=ThinkSettingsV1(
28+
provider=ThinkSettingsV1Provider_OpenAi(type="open_ai", model="gpt-4o-mini"),
29+
prompt="You are a helpful AI assistant.",
30+
),
31+
speak=[SpeakSettingsV1(
32+
provider=SpeakSettingsV1Provider_Deepgram(
33+
type="deepgram",
34+
model="aura-2-arcas-en", # <-- choose voice here
35+
),
36+
)],
37+
),
38+
)
39+
40+
agent.send_settings(settings)
41+
print("Voice agent configured with custom TTS:")
42+
print(" Speak: aura-2-arcas-en (clear, professional male voice)")
43+
44+
45+
if __name__ == "__main__":
46+
main()
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import subprocess
2+
from pathlib import Path
3+
4+
5+
def test_example_runs():
6+
"""Runs the example and verifies it produces output."""
7+
example = Path(__file__).parent / "example.py"
8+
result = subprocess.run(
9+
["python", str(example)],
10+
capture_output=True,
11+
text=True,
12+
timeout=60,
13+
)
14+
assert result.returncode == 0, (
15+
f"Example failed\nSTDOUT: {result.stdout}\nSTDERR: {result.stderr}"
16+
)
17+
assert result.stdout.strip(), "Example produced no output"
18+
assert len(result.stdout.strip()) > 10, "Output seems too short"

0 commit comments

Comments
 (0)