zoya23 commited on
Commit
1623b7c
·
verified ·
1 Parent(s): dbf7916

Update agents/voice_agent.py

Browse files
Files changed (1) hide show
  1. agents/voice_agent.py +17 -0
agents/voice_agent.py CHANGED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()