0

I'm creating a program that recognizes my voice saying: Open * name of a program * and it opens the program. I have a script to decrypt the name of all installed programs, but I do not know how to get what I want by taking this information.

import speech_recognition as sr

r = sr.Recognizer()

with sr.Microphone() as s:
    r.adjust_for_ambient_noise(s)
    while True:
        audio = r.listen(s)
        try:
            speech = r.recognize_google(audio, language = 'en-US')
            speech = str(speech)
            speech = speech.lower()
            print('Você disse: ' + speech)
            if 'bash' in speech:
                #Should open the GitBash
            if 'mozilla' in speech:
                #Should open the Mozilla
        except:
            pass

I hope the program opens the program to speak

hem
  • 1,012
  • 6
  • 11

1 Answers1

0

If you know how to open the program from the command line, we can use the OS package to run these commands. Hope this helps!

import os
os.system("COMMAND TO OPEN PROGRAM FROM COMMAND LINE")

We need a way to list all of the files in a particular directory (programs directory in this case) The following code helps us do this.

import os
def listAllFiles(path):
    if os.path.isfile(path):
        return [ path ]
    else:
        files = [ ]
        for filename in os.listdir(path):
            files += listAllFiles(path + "/" + filename)
        return files

print(listAllFiles("Documents"))
  • Unfortunately to open a specific program by cmd, I need to know the directory where the EXE program is, but thanks! – Guilherme Cunha May 06 '19 at 04:13
  • Edited the post. Now you can list all files in a directory (it finds nested files too, so you can call this program from the home directory). It prints out the path to the file too! Hope this helps :) – Anish Krishnan May 06 '19 at 16:45
  • I tried to use this code, but when I sent the C: / Program Files directory, I received the error: File "C:/Users/Guilherme/Documents/Repositorios/AssistenteVirtual/outro.py", line 15, in listAllFiles for filename in os.listdir(path): PermissionError: [WinError 5] Acesso negado: 'C:/Program Files/Arquivos Comuns' – Guilherme Cunha May 07 '19 at 04:13
  • https://stackoverflow.com/questions/26091530/permissionerror-winerror-5-access-is-denied-python-using-moviepy-to-write-gif – Anish Krishnan May 07 '19 at 18:06