services(cartesia): allow output_format and model_id
This commit is contained in:
@@ -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}")
|
||||
|
||||
Reference in New Issue
Block a user