1

I am creating a personal assistant to open apps with my voice. I want it to always keep hearing so when it hears "Hello Windows" it wakes up, but i don't want it to keep printing Exception because it is either bad practice or I have a feeling that it could reach to a point that all this continuous printing will take up a lot of memory?

import speech_recognition as sr
import pyttsx3

WAKE = "hello windows"


def speak(text):
    engine = pyttsx3.init()
    engine.say(text)
    engine.runAndWait()


def get_audio():
    r = sr.Recognizer()
    with sr.Microphone() as source:
        audio = r.listen(source)
        said = ""

        try:
            said = r.recognize_google(audio)
            print(said)
        except Exception:
            print("Exception")

    return said.lower()


a = True
while a:
    text = get_audio().lower()

    if text.count(WAKE) > 0:
        speak("Hello")
AfterHover
  • 97
  • 2
  • 12

0 Answers0