Chaitanya895 commited on
Commit
7a2393e
·
verified ·
1 Parent(s): 9975475

Update models/speech_interface.py

Browse files
Files changed (1) hide show
  1. 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
- import pyttsx3
 
 
 
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
- try:
63
- self.tts_engine = pyttsx3.init()
64
- self.tts_engine.setProperty('rate', 150) # Speed of speech
65
- self.tts_engine.setProperty('volume', 0.9) # Volume level
66
- except Exception as e:
67
- logger.warning(f"Could not initialize TTS engine: {e}")
 
 
 
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: