tts: fix metrics and TTSStoppedFrame frame in HTTP services
Fixes #1247
This commit is contained in:
@@ -27,6 +27,9 @@ stt = DeepgramSTTService(..., live_options=LiveOptions(model="nova-2-general"))
|
|||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
- Fixed an issue that was causing HTTP TTS services to push `TTSStoppedFrame`
|
||||||
|
more than once.
|
||||||
|
|
||||||
- Fixed a `FishAudioTTSService` issue where `TTSStoppedFrame` was not being
|
- Fixed a `FishAudioTTSService` issue where `TTSStoppedFrame` was not being
|
||||||
pushed.
|
pushed.
|
||||||
|
|
||||||
|
|||||||
@@ -364,9 +364,6 @@ class CartesiaHttpTTSService(TTSService):
|
|||||||
async def run_tts(self, text: str) -> AsyncGenerator[Frame, None]:
|
async def run_tts(self, text: str) -> AsyncGenerator[Frame, None]:
|
||||||
logger.debug(f"Generating TTS: [{text}]")
|
logger.debug(f"Generating TTS: [{text}]")
|
||||||
|
|
||||||
await self.start_ttfb_metrics()
|
|
||||||
yield TTSStartedFrame()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
voice_controls = None
|
voice_controls = None
|
||||||
if self._settings["speed"] or self._settings["emotion"]:
|
if self._settings["speed"] or self._settings["emotion"]:
|
||||||
@@ -376,6 +373,8 @@ class CartesiaHttpTTSService(TTSService):
|
|||||||
if self._settings["emotion"]:
|
if self._settings["emotion"]:
|
||||||
voice_controls["emotion"] = self._settings["emotion"]
|
voice_controls["emotion"] = self._settings["emotion"]
|
||||||
|
|
||||||
|
await self.start_ttfb_metrics()
|
||||||
|
|
||||||
output = await self._client.tts.sse(
|
output = await self._client.tts.sse(
|
||||||
model_id=self._model_name,
|
model_id=self._model_name,
|
||||||
transcript=text,
|
transcript=text,
|
||||||
@@ -386,14 +385,17 @@ class CartesiaHttpTTSService(TTSService):
|
|||||||
_experimental_voice_controls=voice_controls,
|
_experimental_voice_controls=voice_controls,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
await self.start_tts_usage_metrics(text)
|
||||||
|
|
||||||
|
yield TTSStartedFrame()
|
||||||
|
|
||||||
frame = TTSAudioRawFrame(
|
frame = TTSAudioRawFrame(
|
||||||
audio=output["audio"], sample_rate=self.sample_rate, num_channels=1
|
audio=output["audio"], sample_rate=self.sample_rate, num_channels=1
|
||||||
)
|
)
|
||||||
|
|
||||||
yield frame
|
yield frame
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"{self} exception: {e}")
|
logger.error(f"{self} exception: {e}")
|
||||||
|
finally:
|
||||||
await self.start_tts_usage_metrics(text)
|
await self.stop_ttfb_metrics()
|
||||||
|
yield TTSStoppedFrame()
|
||||||
await self.stop_ttfb_metrics()
|
|
||||||
yield TTSStoppedFrame()
|
|
||||||
|
|||||||
@@ -566,18 +566,16 @@ class ElevenLabsHttpTTSService(TTSService):
|
|||||||
return
|
return
|
||||||
|
|
||||||
await self.start_tts_usage_metrics(text)
|
await self.start_tts_usage_metrics(text)
|
||||||
|
|
||||||
yield TTSStartedFrame()
|
yield TTSStartedFrame()
|
||||||
|
|
||||||
async for chunk in response.content:
|
async for chunk in response.content:
|
||||||
if chunk:
|
if chunk:
|
||||||
await self.stop_ttfb_metrics()
|
await self.stop_ttfb_metrics()
|
||||||
yield TTSAudioRawFrame(chunk, self.sample_rate, 1)
|
yield TTSAudioRawFrame(chunk, self.sample_rate, 1)
|
||||||
|
|
||||||
yield TTSStoppedFrame()
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error in run_tts: {e}")
|
logger.error(f"Error in run_tts: {e}")
|
||||||
yield ErrorFrame(error=str(e))
|
yield ErrorFrame(error=str(e))
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
await self.stop_ttfb_metrics()
|
||||||
yield TTSStoppedFrame()
|
yield TTSStoppedFrame()
|
||||||
|
|||||||
@@ -397,6 +397,7 @@ class PlayHTHttpTTSService(TTSService):
|
|||||||
await self.start_tts_usage_metrics(text)
|
await self.start_tts_usage_metrics(text)
|
||||||
|
|
||||||
yield TTSStartedFrame()
|
yield TTSStartedFrame()
|
||||||
|
|
||||||
async for chunk in playht_gen:
|
async for chunk in playht_gen:
|
||||||
# skip the RIFF header.
|
# skip the RIFF header.
|
||||||
if in_header:
|
if in_header:
|
||||||
@@ -416,6 +417,8 @@ class PlayHTHttpTTSService(TTSService):
|
|||||||
await self.stop_ttfb_metrics()
|
await self.stop_ttfb_metrics()
|
||||||
frame = TTSAudioRawFrame(chunk, self.sample_rate, 1)
|
frame = TTSAudioRawFrame(chunk, self.sample_rate, 1)
|
||||||
yield frame
|
yield frame
|
||||||
yield TTSStoppedFrame()
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"{self} error generating TTS: {e}")
|
logger.error(f"{self} error generating TTS: {e}")
|
||||||
|
finally:
|
||||||
|
await self.stop_ttfb_metrics()
|
||||||
|
yield TTSStoppedFrame()
|
||||||
|
|||||||
@@ -387,9 +387,6 @@ class RimeHttpTTSService(TTSService):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
await self.start_ttfb_metrics()
|
await self.start_ttfb_metrics()
|
||||||
await self.start_tts_usage_metrics(text)
|
|
||||||
|
|
||||||
yield TTSStartedFrame()
|
|
||||||
|
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
async with session.post(self._base_url, json=payload, headers=headers) as response:
|
async with session.post(self._base_url, json=payload, headers=headers) as response:
|
||||||
@@ -399,6 +396,10 @@ class RimeHttpTTSService(TTSService):
|
|||||||
yield ErrorFrame(error=error_message)
|
yield ErrorFrame(error=error_message)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
await self.start_tts_usage_metrics(text)
|
||||||
|
|
||||||
|
yield TTSStartedFrame()
|
||||||
|
|
||||||
# Process the streaming response
|
# Process the streaming response
|
||||||
chunk_size = 8192
|
chunk_size = 8192
|
||||||
first_chunk = True
|
first_chunk = True
|
||||||
@@ -411,12 +412,9 @@ class RimeHttpTTSService(TTSService):
|
|||||||
if chunk:
|
if chunk:
|
||||||
frame = TTSAudioRawFrame(chunk, self.sample_rate, 1)
|
frame = TTSAudioRawFrame(chunk, self.sample_rate, 1)
|
||||||
yield frame
|
yield frame
|
||||||
|
|
||||||
yield TTSStoppedFrame()
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception(f"Error generating TTS: {e}")
|
logger.exception(f"Error generating TTS: {e}")
|
||||||
yield ErrorFrame(error=f"Rime TTS error: {str(e)}")
|
yield ErrorFrame(error=f"Rime TTS error: {str(e)}")
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
await self.stop_ttfb_metrics()
|
||||||
yield TTSStoppedFrame()
|
yield TTSStoppedFrame()
|
||||||
|
|||||||
Reference in New Issue
Block a user