zoya23 commited on
Commit
52ec4d2
·
verified ·
1 Parent(s): 8009a79

Update agents/voice_agent.py

Browse files
Files changed (1) hide show
  1. agents/voice_agent.py +16 -6
agents/voice_agent.py CHANGED
@@ -1,7 +1,17 @@
1
- # voice_agent.py
2
- from gtts import gTTS
3
 
4
- def text_to_speech(text, filename="output.mp3"):
5
- tts = gTTS(text)
6
- tts.save(filename)
7
- return filename
 
 
 
 
 
 
 
 
 
 
 
1
+ import speech_recognition as sr
2
+ import pyttsx3
3
 
4
+ def speech_to_text():
5
+ recognizer = sr.Recognizer()
6
+ with sr.Microphone() as source:
7
+ print("🎤 Listening...")
8
+ audio = recognizer.listen(source)
9
+ try:
10
+ return recognizer.recognize_google(audio)
11
+ except:
12
+ return "Could not understand."
13
+
14
+ def text_to_speech(text):
15
+ engine = pyttsx3.init()
16
+ engine.say(text)
17
+ engine.runAndWait()