Skip to content

Commit

Permalink
Add timeout to openai TTS call
Browse files Browse the repository at this point in the history
  • Loading branch information
paulovcmedeiros committed Nov 16, 2023
1 parent aa7ef16 commit ebd701a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
license = "MIT"
name = "pyrobbot"
readme = "README.md"
version = "0.3.1"
version = "0.3.2"

[build-system]
build-backend = "poetry.core.masonry.api"
Expand Down
3 changes: 3 additions & 0 deletions pyrobbot/voice_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ def _assistant_still_talking(self):
@retry_api_call()
def _tts_openai(self, text):
"""Convert text to speech using OpenAI's TTS."""
logger.debug("OpenAI TTS received: '{}'", text)
text = text.strip()
client = OpenAI()

Expand All @@ -266,6 +267,7 @@ def _tts_openai(self, text):
model=openai_tts_model,
voice=self.openai_tts_voice,
response_format="mp3",
timeout=self.timeout,
)

mp3_buffer = io.BytesIO()
Expand All @@ -281,6 +283,7 @@ def _tts_openai(self, text):
sound.export(wav_buffer, format="wav")
wav_buffer.seek(0)

logger.debug("OpenAI TTS done for '{}'", text)
return wav_buffer

def _tts_google(self, text):
Expand Down

0 comments on commit ebd701a

Please sign in to comment.