Spaces:
Sleeping
Sleeping
Update models/speech_interface.py
Browse files- models/speech_interface.py +13 -7
models/speech_interface.py
CHANGED
|
@@ -1,6 +1,9 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import speech_recognition as sr
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
| 4 |
from gtts import gTTS
|
| 5 |
import io
|
| 6 |
import tempfile
|
|
@@ -59,12 +62,15 @@ class SpeechInterface:
|
|
| 59 |
}
|
| 60 |
|
| 61 |
# Initialize text-to-speech engine
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
| 68 |
self.tts_engine = None
|
| 69 |
|
| 70 |
def has_tts(self) -> bool:
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import speech_recognition as sr
|
| 3 |
+
try:
|
| 4 |
+
import pyttsx3
|
| 5 |
+
except Exception:
|
| 6 |
+
pyttsx3 = None
|
| 7 |
from gtts import gTTS
|
| 8 |
import io
|
| 9 |
import tempfile
|
|
|
|
| 62 |
}
|
| 63 |
|
| 64 |
# Initialize text-to-speech engine
|
| 65 |
+
if pyttsx3 is not None:
|
| 66 |
+
try:
|
| 67 |
+
self.tts_engine = pyttsx3.init()
|
| 68 |
+
self.tts_engine.setProperty('rate', 150) # Speed of speech
|
| 69 |
+
self.tts_engine.setProperty('volume', 0.9) # Volume level
|
| 70 |
+
except Exception as e:
|
| 71 |
+
logger.warning(f"Could not initialize TTS engine: {e}")
|
| 72 |
+
self.tts_engine = None
|
| 73 |
+
else:
|
| 74 |
self.tts_engine = None
|
| 75 |
|
| 76 |
def has_tts(self) -> bool:
|