From b515c28417795737124492028305e63d60ffa0c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Tue, 4 Jun 2024 19:24:33 -0700 Subject: [PATCH] services(cartesia): allow output_format and model_id --- CHANGELOG.md | 3 +++ .../foundational/07d-interruptible-cartesia.py | 4 +++- src/pipecat/services/cartesia.py | 16 ++++++++++------ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74b7aafcf..d82f66bd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- Allow passing `output_format` and `model_id` to `CartesiaTTSService` to change + audio sample format and the model to use. + - Added `DailyRESTHelper` which helps you create Daily rooms and tokens in an easy way. diff --git a/examples/foundational/07d-interruptible-cartesia.py b/examples/foundational/07d-interruptible-cartesia.py index d9e5128d5..39a77492b 100644 --- a/examples/foundational/07d-interruptible-cartesia.py +++ b/examples/foundational/07d-interruptible-cartesia.py @@ -39,6 +39,7 @@ async def main(room_url: str, token): "Respond bot", DailyParams( audio_out_enabled=True, + audio_out_sample_rate=44100, transcription_enabled=True, vad_enabled=True, vad_analyzer=SileroVADAnalyzer() @@ -47,7 +48,8 @@ async def main(room_url: str, token): tts = CartesiaTTSService( api_key=os.getenv("CARTESIA_API_KEY"), - voice_name="Barbershop Man" + voice_name="British Lady", + output_format="pcm_44100" ) llm = OpenAILLMService( diff --git a/src/pipecat/services/cartesia.py b/src/pipecat/services/cartesia.py index 86baa7a3e..f2d8c9b14 100644 --- a/src/pipecat/services/cartesia.py +++ b/src/pipecat/services/cartesia.py @@ -21,11 +21,15 @@ class CartesiaTTSService(TTSService): *, api_key: str, voice_name: str, + model_id: str = "upbeat-moon", + output_format: str = "pcm_16000", **kwargs): super().__init__(**kwargs) self._api_key = api_key self._voice_name = voice_name + self._model_id = model_id + self._output_format = output_format try: self._client = AsyncCartesiaTTS(api_key=self._api_key) @@ -40,14 +44,14 @@ class CartesiaTTSService(TTSService): try: chunk_generator = await self._client.generate( - transcript=text, voice=self._voice, stream=True, - model_id="upbeat-moon", data_rtype='array', output_format='pcm_16000', - # a chunk_time of 0.1 seems to be the default. there are small audio pops/gaps which - # we need to debug - chunk_time=0.1 + stream=True, + transcript=text, + voice=self._voice, + model_id=self._model_id, + output_format=self._output_format, ) async for chunk in chunk_generator: - yield AudioRawFrame(chunk['audio'], 16000, 1) + yield AudioRawFrame(chunk["audio"], chunk["sampling_rate"], 1) except Exception as e: logger.error(f"Cartesia exception: {e}")