|
| 1 | +""" |
| 2 | +Recipe: Configure TTS Voice (Voice Agents v1) |
| 3 | +=============================================== |
| 4 | +Demonstrates selecting a specific aura-2 voice model for the agent's |
| 5 | +speech output in the speak stage of the pipeline. |
| 6 | +
|
| 7 | +The `speak` component controls which TTS model synthesises the agent's |
| 8 | +responses. This recipe uses aura-2-arcas-en — a different voice from |
| 9 | +the default — to demonstrate voice customisation. |
| 10 | +""" |
| 11 | + |
| 12 | +from deepgram import DeepgramClient |
| 13 | +from deepgram.agent.v1.types import ( |
| 14 | + AgentV1Settings, AgentV1SettingsAgent, |
| 15 | + AgentV1SettingsAgentListen, AgentV1SettingsAgentListenProvider_V1, |
| 16 | + AgentV1SettingsAudio, AgentV1SettingsAudioInput, |
| 17 | +) |
| 18 | +from deepgram.core.events import EventType |
| 19 | +from deepgram.types.speak_settings_v1 import SpeakSettingsV1 |
| 20 | +from deepgram.types.speak_settings_v1provider import SpeakSettingsV1Provider_Deepgram |
| 21 | +from deepgram.types.think_settings_v1 import ThinkSettingsV1 |
| 22 | +from deepgram.types.think_settings_v1provider import ThinkSettingsV1Provider_OpenAi |
| 23 | + |
| 24 | + |
| 25 | +def main(): |
| 26 | + client = DeepgramClient() # reads DEEPGRAM_API_KEY from environment |
| 27 | + |
| 28 | + with client.agent.v1.connect() as agent: |
| 29 | + settings = AgentV1Settings( |
| 30 | + audio=AgentV1SettingsAudio( |
| 31 | + input=AgentV1SettingsAudioInput(encoding="linear16", sample_rate=24000) |
| 32 | + ), |
| 33 | + agent=AgentV1SettingsAgent( |
| 34 | + listen=AgentV1SettingsAgentListen( |
| 35 | + provider=AgentV1SettingsAgentListenProvider_V1(type="deepgram", model="nova-3") |
| 36 | + ), |
| 37 | + think=ThinkSettingsV1( |
| 38 | + provider=ThinkSettingsV1Provider_OpenAi(type="open_ai", model="gpt-4o-mini"), |
| 39 | + prompt="You are a helpful AI assistant.", |
| 40 | + ), |
| 41 | + speak=SpeakSettingsV1( |
| 42 | + provider=SpeakSettingsV1Provider_Deepgram( |
| 43 | + type="deepgram", |
| 44 | + model="aura-2-arcas-en", # <-- THIS is the feature: selecting the TTS voice |
| 45 | + ) |
| 46 | + ), |
| 47 | + ), |
| 48 | + ) |
| 49 | + |
| 50 | + agent.send_settings(settings) |
| 51 | + print("Custom TTS settings sent (aura-2-arcas-en)") |
| 52 | + |
| 53 | + def on_message(message): |
| 54 | + if not isinstance(message, bytes): |
| 55 | + msg_type = getattr(message, "type", type(message).__name__) |
| 56 | + print(f"Event: {msg_type}") |
| 57 | + |
| 58 | + agent.on(EventType.MESSAGE, on_message) |
| 59 | + agent.on(EventType.ERROR, lambda e: print(f"Error: {e}")) |
| 60 | + agent.start_listening() |
| 61 | + |
| 62 | + |
| 63 | +if __name__ == "__main__": |
| 64 | + main() |
0 commit comments