Skip to content

Commit

Permalink
Apply Ruff formater
Browse files Browse the repository at this point in the history
  • Loading branch information
golbin committed Sep 26, 2024
1 parent 49f2123 commit d05717a
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions src/pipecat/services/cartesia.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,16 @@ class InputParams(BaseModel):
emotion: Optional[List[str]] = []

def __init__(
self,
*,
api_key: str,
voice_id: str,
cartesia_version: str = "2024-06-10",
url: str = "wss://api.cartesia.ai/tts/websocket",
model_id: str = "sonic-english",
params: InputParams = InputParams(),
**kwargs):
self,
*,
api_key: str,
voice_id: str,
cartesia_version: str = "2024-06-10",
url: str = "wss://api.cartesia.ai/tts/websocket",
model_id: str = "sonic-english",
params: InputParams = InputParams(),
**kwargs,
):
# Aggregating sentences still gives cleaner-sounding results and fewer
# artifacts than streaming one word at a time. On average, waiting for a
# full sentence should only "cost" us 15ms or so with GPT-4o or a Llama
Expand All @@ -91,7 +92,10 @@ def __init__(
# can use those to generate text frames ourselves aligned with the
# playout timing of the audio!
super().__init__(
aggregate_sentences=True, push_text_frames=False, sample_rate=params.sample_rate, **kwargs
aggregate_sentences=True,
push_text_frames=False,
sample_rate=params.sample_rate,
**kwargs,
)

self._api_key = api_key
Expand Down Expand Up @@ -137,11 +141,10 @@ async def set_language(self, language: Language):
logger.debug(f"Switching TTS language to: [{language}]")
self._language = language_to_cartesia_language(language)

def _build_msg(self, text: str = "", continue_transcript: bool = True, add_timestamps: bool = True):
voice_config = {
"mode": "id",
"id": self._voice_id
}
def _build_msg(
self, text: str = "", continue_transcript: bool = True, add_timestamps: bool = True
):
voice_config = {"mode": "id", "id": self._voice_id}

if self._speed or self._emotion:
voice_config["__experimental_controls"] = {}
Expand Down Expand Up @@ -236,8 +239,7 @@ async def _receive_task_handler(self):
await self.add_word_timestamps([("LLMFullResponseEndFrame", 0)])
elif msg["type"] == "timestamps":
await self.add_word_timestamps(
list(zip(msg["word_timestamps"]["words"],
msg["word_timestamps"]["start"]))
list(zip(msg["word_timestamps"]["words"], msg["word_timestamps"]["start"]))
)
elif msg["type"] == "chunk":
await self.stop_ttfb_metrics()
Expand All @@ -254,8 +256,7 @@ async def _receive_task_handler(self):
await self.stop_all_metrics()
await self.push_error(ErrorFrame(f'{self} error: {msg["error"]}'))
else:
logger.error(
f"Cartesia error, unknown message type: {msg}")
logger.error(f"Cartesia error, unknown message type: {msg}")
except asyncio.CancelledError:
pass
except Exception as e:
Expand Down Expand Up @@ -379,7 +380,7 @@ async def run_tts(self, text: str) -> AsyncGenerator[Frame, None]:
output_format=self._output_format,
language=self._language,
stream=False,
_experimental_voice_controls=voice_controls
_experimental_voice_controls=voice_controls,
)

await self.stop_ttfb_metrics()
Expand Down

0 comments on commit d05717a

Please sign in to comment.