Merge pull request #1191 from pipecat-ai/mb/azure-tts-error-handling
Improve AzureTTSService error handling
This commit is contained in:
@@ -20,6 +20,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
- Improved error handling in `AzureTTSService` to properly detect and log
|
||||||
|
synthesis cancellation errors.
|
||||||
|
|
||||||
- Enhanced `WhisperSTTService` with full language support and improved model
|
- Enhanced `WhisperSTTService` with full language support and improved model
|
||||||
documentation.
|
documentation.
|
||||||
|
|
||||||
|
|||||||
@@ -577,35 +577,43 @@ class AzureTTSService(AzureBaseTTSService):
|
|||||||
logger.debug(f"Generating TTS: [{text}]")
|
logger.debug(f"Generating TTS: [{text}]")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await self.start_ttfb_metrics()
|
if self._speech_synthesizer is None:
|
||||||
yield TTSStartedFrame()
|
error_msg = "Speech synthesizer not initialized."
|
||||||
|
logger.error(error_msg)
|
||||||
|
yield ErrorFrame(error_msg)
|
||||||
|
return
|
||||||
|
|
||||||
ssml = self._construct_ssml(text)
|
try:
|
||||||
|
await self.start_ttfb_metrics()
|
||||||
|
yield TTSStartedFrame()
|
||||||
|
|
||||||
# Start synthesis
|
ssml = self._construct_ssml(text)
|
||||||
self._speech_synthesizer.speak_ssml_async(ssml)
|
self._speech_synthesizer.speak_ssml_async(ssml)
|
||||||
|
await self.start_tts_usage_metrics(text)
|
||||||
|
|
||||||
await self.start_tts_usage_metrics(text)
|
# Stream audio chunks as they arrive
|
||||||
|
while True:
|
||||||
|
chunk = await self._audio_queue.get()
|
||||||
|
if chunk is None: # End of stream
|
||||||
|
break
|
||||||
|
|
||||||
# Stream audio chunks as they arrive
|
await self.stop_ttfb_metrics()
|
||||||
while True:
|
yield TTSAudioRawFrame(
|
||||||
chunk = await self._audio_queue.get()
|
audio=chunk,
|
||||||
if chunk is None: # End of stream
|
sample_rate=self.sample_rate,
|
||||||
break
|
num_channels=1,
|
||||||
|
)
|
||||||
|
|
||||||
await self.stop_ttfb_metrics()
|
yield TTSStoppedFrame()
|
||||||
|
|
||||||
yield TTSAudioRawFrame(
|
except Exception as e:
|
||||||
audio=chunk,
|
logger.error(f"{self} error during synthesis: {e}")
|
||||||
sample_rate=self.sample_rate,
|
yield TTSStoppedFrame()
|
||||||
num_channels=1,
|
# Could add reconnection logic here if needed
|
||||||
)
|
return
|
||||||
|
|
||||||
yield TTSStoppedFrame()
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"{self} error generating TTS: {e}")
|
logger.error(f"{self} exception: {e}")
|
||||||
yield ErrorFrame(f"{self} error: {str(e)}")
|
|
||||||
|
|
||||||
|
|
||||||
class AzureHttpTTSService(AzureBaseTTSService):
|
class AzureHttpTTSService(AzureBaseTTSService):
|
||||||
|
|||||||
Reference in New Issue
Block a user