After converting the input voice into text, a program that outputs the appropriate answer (a line written in text) back to voice I'm making it
Right now, I'm making sure that I keep going through infinite loops through the while door I want to react when a specific word comes in as an event, not like this. What should I do?
import speech_recognition as sr
import pyttsx3
import requests
import urllib
from bs4 import BeautifulSoup
def Saying(msg):
engine = pyttsx3.init() # voice engine initialization
voices = engine.getProperty('voices')
volume = engine.getProperty('volume')
rate = engine.getProperty('rate')
print('rate = ',rate)
engine.setProperty('rate', 180)
engine.say(msg)
engine.runAndWait()
def main():
while True:
r = sr.Recognizer()
with sr.Microphone() as source:
print("Speak:")
try:
audio = r.listen(source, timeout=0, phrase_time_limit=2.5)
print("You said: " + r.recognize_google(audio, language="ko-KR"))
ifr.recognize_google(audio, language="ko-KR") == 'Tell me the weather':
print('Let me know the weather' has been entered.')
#get_weather()
ifr.recognize_google(audio, language="ko-KR") == 'Jung Won':
print('Jung Won-ah' entered.')
Saying ('Did you call me?')
else:
print('Unknown command.')
Saying ('I don't know what you're talking about')
except sr.UnknownValueError:
print("Google Speech Recognition could not understand audio")
except sr.RequestError as e:
print("Could not request results from Google Speech Recognition service")
#Main part
if __name__ == "__main__":
main()
Your question can be called background listening, but when I searched,
© 2024 OneMinuteCode. All rights reserved.