How to open an app with Speech Recognition?

Asked

Viewed 25 times

-1

I would like to create a mini application that opens a file or even another application through Speech recognition, ie I would open it and when I gave the example command:

if 'open' in command:
    talk('Openning program')
    # código da ação de abrir o programa

We can discard the function part of the above code, since it is already set. I would just like to know which library and which command would be for the action of opening one program from another.

I appreciate all your help!

1 answer

1

To open a file in OS - using its default program - use the function startfile module os, passing as argument the file path you want to open, along with the file extension. See the example below:

with sr.Microphone() as source:
    audio = microfone.listen(source)

try:
    text = recognizer.recognize_google(audio, language = "pt-BR").lower()
    if text.startswith("abrir"): os.startfile(text.split(maxsplit = 1)[-1])

except: 
    print("Parece que houve algum problema no reconhecimento da voz...")

Browser other questions tagged

You are not signed in. Login or sign up in order to post.