DSatishchandra commited on
Commit
f1d3292
1 Parent(s): 6401732

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -1,14 +1,12 @@
1
  import gradio as gr
2
  import speech_recognition as sr
3
- import pyttsx3
 
4
  from transformers import pipeline
5
 
6
  # Initialize recognizer for speech recognition
7
  recognizer = sr.Recognizer()
8
 
9
- # Initialize text-to-speech engine
10
- engine = pyttsx3.init()
11
-
12
  # Initialize Hugging Face NLP pipeline for intent recognition
13
  nlp = pipeline("zero-shot-classification")
14
 
@@ -32,8 +30,12 @@ def recognize_speech(audio):
32
  try:
33
  text = recognizer.recognize_google(audio)
34
  response = process_order(text)
35
- engine.say(response) # TTS response
36
- engine.runAndWait()
 
 
 
 
37
  return response
38
  except Exception as e:
39
  return "Sorry, I could not understand."
 
1
  import gradio as gr
2
  import speech_recognition as sr
3
+ from gtts import gTTS
4
+ import os
5
  from transformers import pipeline
6
 
7
  # Initialize recognizer for speech recognition
8
  recognizer = sr.Recognizer()
9
 
 
 
 
10
  # Initialize Hugging Face NLP pipeline for intent recognition
11
  nlp = pipeline("zero-shot-classification")
12
 
 
30
  try:
31
  text = recognizer.recognize_google(audio)
32
  response = process_order(text)
33
+
34
+ # Using gTTS to respond back with speech
35
+ tts = gTTS(text=response, lang='en')
36
+ tts.save("response.mp3")
37
+ os.system("mpg321 response.mp3") # Play the response (for local environments)
38
+
39
  return response
40
  except Exception as e:
41
  return "Sorry, I could not understand."