Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added __pycache__/config.cpython-313.pyc
Binary file not shown.
Binary file added __pycache__/tts_utils.cpython-313.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ numpy
Pillow
SpeechRecognition
pyaudio
playsound
pydub
python-dotenv
16 changes: 11 additions & 5 deletions tts_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from config import TTS_ENGINE
import pyttsx3
from gtts import gTTS
from playsound import playsound
from pydub import AudioSegment
import winsound
import tempfile
import os

Expand All @@ -34,10 +35,15 @@ def speak(text):
elif TTS_ENGINE == "gTTS":
try:
tts = gTTS(text=text, lang='en')
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp:
tts.save(tmp.name)
playsound(tmp.name)
os.remove(tmp.name)
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_mp3:
tts.save(tmp_mp3.name)
# Convert mp3 to wav
sound = AudioSegment.from_mp3(tmp_mp3.name)
tmp_wav = tmp_mp3.name.replace('.mp3', '.wav')
sound.export(tmp_wav, format="wav")
winsound.PlaySound(tmp_wav, winsound.SND_FILENAME)
os.remove(tmp_mp3.name)
os.remove(tmp_wav)
except Exception as e:
print(f"[gTTS Error] {e}. Falling back to pyttsx3.")
fallback_speak(text)
Expand Down