Skip to content

Commit

Permalink
Add speed and emotion options for Cartesia.
Browse files Browse the repository at this point in the history
  • Loading branch information
golbin committed Aug 31, 2024
1 parent 7c342f7 commit 3c716f6
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/pipecat/services/cartesia.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ def __init__(
encoding: str = "pcm_s16le",
sample_rate: int = 16000,
language: str = "en",
speed: str = None,
emotion: list = None,
**kwargs):
super().__init__(**kwargs)

Expand All @@ -99,6 +101,8 @@ def __init__(
"sample_rate": sample_rate,
}
self._language = language
self._speed = speed
self._emotion = emotion

self._websocket = None
self._context_id = None
Expand Down Expand Up @@ -249,15 +253,24 @@ async def run_tts(self, text: str) -> AsyncGenerator[Frame, None]:
await self.start_ttfb_metrics()
self._context_id = str(uuid.uuid4())

voice_config = {
"mode": "id",
"id": self._voice_id
}

if self._speed or self._emotion:
voice_config["__experimental_controls"] = {}
if self._speed:
voice_config["__experimental_controls"]["speed"] = self._speed
if self._emotion:
voice_config["__experimental_controls"]["emotion"] = self._emotion

msg = {
"transcript": text + " ",
"continue": True,
"context_id": self._context_id,
"model_id": self._model_id,
"voice": {
"mode": "id",
"id": self._voice_id
},
"voice": voice_config,
"output_format": self._output_format,
"language": self._language,
"add_timestamps": True,
Expand Down

0 comments on commit 3c716f6

Please sign in to comment.