-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtts_comparison.py
182 lines (151 loc) · 5.84 KB
/
tts_comparison.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import logging
from pathlib import Path
from dotenv import load_dotenv
from livekit.agents import JobContext, WorkerOptions, cli
from livekit.agents.llm import function_tool
from livekit.agents.voice import Agent, AgentSession
from livekit.plugins import deepgram, openai, rime, elevenlabs, cartesia, playai, silero
logger = logging.getLogger("tts-comparison")
logger.setLevel(logging.INFO)
load_dotenv(dotenv_path=Path(__file__).parent.parent / '.env')
### We're not including the OpenAI TTS provider here, since it uses a different sample rate.
### See openai_tts.py for an example of how to use it.
class RimeAgent(Agent):
def __init__(self) -> None:
super().__init__(
instructions="""
You are a helpful assistant communicating through voice.
You are currently using the Rime TTS provider.
You can switch to a different TTS provider if asked.
Don't use any unpronouncable characters.
""",
stt=deepgram.STT(),
llm=openai.LLM(model="gpt-4o"),
tts=rime.TTS(
sample_rate=44100,
model="mistv2",
speaker="abbie"
),
vad=silero.VAD.load()
)
async def on_enter(self) -> None:
"""Called when switching to this provider"""
await self.session.say("Hello! I'm now using the Rime TTS voice. How does it sound?")
@function_tool
async def switch_to_elevenlabs(self):
"""Switch to ElevenLabs TTS voice"""
return ElevenLabsAgent()
@function_tool
async def switch_to_cartesia(self):
"""Switch to Cartesia TTS voice"""
return CartesiaAgent()
@function_tool
async def switch_to_playai(self):
"""Switch to PlayAI TTS voice"""
return PlayAIAgent()
class ElevenLabsAgent(Agent):
def __init__(self) -> None:
super().__init__(
instructions="""
You are a helpful assistant communicating through voice.
You are currently using the ElevenLabs TTS provider.
You can switch to a different TTS provider if asked.
Don't use any unpronouncable characters.
""",
stt=deepgram.STT(),
llm=openai.LLM(model="gpt-4o"),
tts=elevenlabs.TTS(
model="eleven_multilingual_v2"
),
vad=silero.VAD.load()
)
async def on_enter(self) -> None:
"""Called when switching to this provider"""
await self.session.say("Hello! I'm now using the ElevenLabs TTS voice. What do you think of how I sound?")
@function_tool
async def switch_to_rime(self):
"""Switch to Rime TTS voice"""
return RimeAgent()
@function_tool
async def switch_to_cartesia(self):
"""Switch to Cartesia TTS voice"""
return CartesiaAgent()
@function_tool
async def switch_to_playai(self):
"""Switch to PlayAI TTS voice"""
return PlayAIAgent()
class CartesiaAgent(Agent):
def __init__(self) -> None:
super().__init__(
instructions="""
You are a helpful assistant communicating through voice.
You are currently using the Cartesia TTS provider.
You can switch to a different TTS provider if asked.
Don't use any unpronouncable characters.
""",
stt=deepgram.STT(),
llm=openai.LLM(model="gpt-4o"),
tts=cartesia.TTS(
sample_rate=44100,
model="sonic-preview",
voice="87bc56aa-ab01-4baa-9071-77d497064686"
),
vad=silero.VAD.load()
)
async def on_enter(self) -> None:
"""Called when switching to this provider"""
await self.session.say("Hello! I'm now using the Cartesia TTS voice. How do I sound to you?")
@function_tool
async def switch_to_rime(self):
"""Switch to Rime TTS voice"""
return RimeAgent()
@function_tool
async def switch_to_elevenlabs(self):
"""Switch to ElevenLabs TTS voice"""
return ElevenLabsAgent()
@function_tool
async def switch_to_playai(self):
"""Switch to PlayAI TTS voice"""
return PlayAIAgent()
class PlayAIAgent(Agent):
def __init__(self) -> None:
super().__init__(
instructions="""
You are a helpful assistant communicating through voice.
You are currently using the PlayAI TTS provider.
You can switch to a different TTS provider if asked.
Don't use any unpronouncable characters.
""",
stt=deepgram.STT(),
llm=openai.LLM(model="gpt-4o"),
tts=playai.TTS(
model="PlayDialog",
sample_rate=44100,
voice="s3://voice-cloning-zero-shot/9f1ee23a-9108-4538-90be-8e62efc195b6/charlessaad/manifest.json"
),
vad=silero.VAD.load()
)
async def on_enter(self) -> None:
"""Called when switching to this provider"""
await self.session.say("Hello! I'm now using the PlayAI TTS voice. What are your thoughts on how I sound?")
@function_tool
async def switch_to_rime(self):
"""Switch to Rime TTS voice"""
return RimeAgent()
@function_tool
async def switch_to_elevenlabs(self):
"""Switch to ElevenLabs TTS voice"""
return ElevenLabsAgent()
@function_tool
async def switch_to_cartesia(self):
"""Switch to Cartesia TTS voice"""
return CartesiaAgent()
async def entrypoint(ctx: JobContext):
await ctx.connect()
session = AgentSession()
await session.start(
agent=RimeAgent(),
room=ctx.room
)
if __name__ == "__main__":
cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))