Skip to content

Commit

Permalink
fix(tts_clients.py): increase TTS_TRIES from 2 to 5 to improve speech…
Browse files Browse the repository at this point in the history
… synthesis reliability

feat(tts_clients.py): add TTS_RETRY_DELAY to introduce a delay between retries for better handling of transient errors
  • Loading branch information
maciejmajek committed Sep 27, 2024
1 parent d93a101 commit 829b91f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/rai_tts/rai_tts/tts_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import logging
import os
import tempfile
import time
from abc import abstractmethod
from typing import Optional

Expand All @@ -26,7 +27,8 @@

logger = logging.getLogger(__name__)

TTS_TRIES = 2
TTS_TRIES = 5
TTS_RETRY_DELAY = 0.5


class TTSClient:
Expand Down Expand Up @@ -75,7 +77,13 @@ def synthesize_speech_to_file(self, text: str) -> str:
except Exception as e:
logger.warn(f"Error occurred during synthesizing speech: {e}.") # type: ignore
tries += 1
audio_data = b"".join(response)
if tries == TTS_TRIES:
logger.error(
f"Failed to synthesize speech after {TTS_TRIES} tries. Creating empty audio file instead."
)
time.sleep(TTS_RETRY_DELAY)

audio_data = b""
return self.save_audio_to_file(audio_data, suffix=".mp3")


Expand Down

0 comments on commit 829b91f

Please sign in to comment.