So i have a voice assistant project i use speech recognition and pytsx3, the problem is the functions repetition, so this is my code
main.py:
import possibilities as ps
clear = lambda: os.system('cls')
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[3].id)
engine.setProperty("rate", 160)
def speak(audio):
engine.say(audio)
engine.runAndWait()
while True:
rec = sr.Recognizer()
with sr.Microphone() as mic:
print("Manini listen...")
audio = rec.listen(mic)
try:
text = rec.recognize_google(audio, language='en')
query = text.lower()
except Exception as e:
print("Manini Listen...")
if 'wikipedia' in query:
ps.wikipediaSer(query)
elif "say" in query:
ps.sayrep(query)
elif 'open youtube' in query:
ps.openyoutube()
possibilties.py:
def wikipediaSer(query):
speak('Searching Wikipedia...')
query = query.replace("wikipedia", "")
results = wikipedia.summary(query, sentences = 2)
speak("According to Wikipedia")
print(results)
speak(results)
def sayrep(query):
say_text = query.replace("say", "")
speak(say_text)
def openyoutube():
speak("Here you go to Youtube\n")
webbrowser.open("youtube.com")
so when I execute the project and say a command Wikipedia par example, Wikipedia code repet 5 times. how I can fix this repetition please.