services(cartesia): allow output_format and model_id

This commit is contained in:
Aleix Conchillo Flaqué
2024-06-04 19:24:33 -07:00
parent 854ffb0323
commit b515c28417
3 changed files with 16 additions and 7 deletions

View File

@@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### 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 - Added `DailyRESTHelper` which helps you create Daily rooms and tokens in an
easy way. easy way.

View File

@@ -39,6 +39,7 @@ async def main(room_url: str, token):
"Respond bot", "Respond bot",
DailyParams( DailyParams(
audio_out_enabled=True, audio_out_enabled=True,
audio_out_sample_rate=44100,
transcription_enabled=True, transcription_enabled=True,
vad_enabled=True, vad_enabled=True,
vad_analyzer=SileroVADAnalyzer() vad_analyzer=SileroVADAnalyzer()
@@ -47,7 +48,8 @@ async def main(room_url: str, token):
tts = CartesiaTTSService( tts = CartesiaTTSService(
api_key=os.getenv("CARTESIA_API_KEY"), api_key=os.getenv("CARTESIA_API_KEY"),
voice_name="Barbershop Man" voice_name="British Lady",
output_format="pcm_44100"
) )
llm = OpenAILLMService( llm = OpenAILLMService(

View File

@@ -21,11 +21,15 @@ class CartesiaTTSService(TTSService):
*, *,
api_key: str, api_key: str,
voice_name: str, voice_name: str,
model_id: str = "upbeat-moon",
output_format: str = "pcm_16000",
**kwargs): **kwargs):
super().__init__(**kwargs) super().__init__(**kwargs)
self._api_key = api_key self._api_key = api_key
self._voice_name = voice_name self._voice_name = voice_name
self._model_id = model_id
self._output_format = output_format
try: try:
self._client = AsyncCartesiaTTS(api_key=self._api_key) self._client = AsyncCartesiaTTS(api_key=self._api_key)
@@ -40,14 +44,14 @@ class CartesiaTTSService(TTSService):
try: try:
chunk_generator = await self._client.generate( chunk_generator = await self._client.generate(
transcript=text, voice=self._voice, stream=True, stream=True,
model_id="upbeat-moon", data_rtype='array', output_format='pcm_16000', transcript=text,
# a chunk_time of 0.1 seems to be the default. there are small audio pops/gaps which voice=self._voice,
# we need to debug model_id=self._model_id,
chunk_time=0.1 output_format=self._output_format,
) )
async for chunk in chunk_generator: async for chunk in chunk_generator:
yield AudioRawFrame(chunk['audio'], 16000, 1) yield AudioRawFrame(chunk["audio"], chunk["sampling_rate"], 1)
except Exception as e: except Exception as e:
logger.error(f"Cartesia exception: {e}") logger.error(f"Cartesia exception: {e}")