gigswar commited on
Commit
3585a12
·
verified ·
1 Parent(s): 9e431d4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -7
app.py CHANGED
@@ -1,15 +1,14 @@
1
  import os
2
  import openai
3
  import gradio as gr
4
- import pyttsx3
5
  import speech_recognition as sr
 
6
  from tempfile import NamedTemporaryFile
7
 
8
  openai.api_key = os.getenv("OPENAI_API_KEY")
9
 
10
- # Initialize the speech recognition and TTS engines
11
  recognizer = sr.Recognizer()
12
- tts_engine = pyttsx3.init()
13
 
14
  # Set up for speech-to-text (STT)
15
  def recognize_speech_from_microphone():
@@ -24,12 +23,12 @@ def recognize_speech_from_microphone():
24
  except sr.RequestError:
25
  return "Sorry, the service is down."
26
 
27
- # Text to Speech (TTS) function
28
  def speak_text(text):
29
  with NamedTemporaryFile(delete=False, suffix='.mp3') as temp_file:
30
  temp_file.close()
31
- tts_engine.save_to_file(text, temp_file.name)
32
- tts_engine.runAndWait()
33
  return temp_file.name
34
 
35
  # GPT-4o Q&A function
@@ -68,4 +67,4 @@ iface = gr.Interface(
68
  )
69
 
70
  if __name__ == "__main__":
71
- iface.launch()
 
1
  import os
2
  import openai
3
  import gradio as gr
 
4
  import speech_recognition as sr
5
+ from gtts import gTTS
6
  from tempfile import NamedTemporaryFile
7
 
8
  openai.api_key = os.getenv("OPENAI_API_KEY")
9
 
10
+ # Initialize the speech recognition engine
11
  recognizer = sr.Recognizer()
 
12
 
13
  # Set up for speech-to-text (STT)
14
  def recognize_speech_from_microphone():
 
23
  except sr.RequestError:
24
  return "Sorry, the service is down."
25
 
26
+ # Text to Speech (TTS) function using gTTS
27
  def speak_text(text):
28
  with NamedTemporaryFile(delete=False, suffix='.mp3') as temp_file:
29
  temp_file.close()
30
+ tts = gTTS(text=text, lang='en')
31
+ tts.save(temp_file.name)
32
  return temp_file.name
33
 
34
  # GPT-4o Q&A function
 
67
  )
68
 
69
  if __name__ == "__main__":
70
+ iface.launch()