Make a personal assistant

Asked

Viewed 80 times

-4

Hello, I am developing a personal assistant in Python, however I would like to use a process similar to that of "OK Google", where when I speak the phrase, the program runs. That is, when I say something similar to "OK Google" the software runs. The program is already all done. I just wanted to know how to open the program when I "call" it.

1 answer

1


First thing you have to do is install in python a speech recognition library, in the case of this example the library is Speechrecognition.

To install:

pip install SpeechRecognition

After a read installed in your documentation

# importa o módulo de reconhecimento de voz
import speech_recognition as sr

# obtém o audio do microfone
r = sr.Recognizer()
with sr.Microphone() as source:
    print("Diga alguma coisa...")
    audio = r.listen(source)

# reconhece a fala usando o Google Speech Recognition.
# o método r.recognize_google(audio) está usando a chave padrão do Google Speech Recognition
# para usar sua chave use a sobrecarga r.recognize_google(audio, chave) onde
# chave é uma string contendo sua chave para a API Google Speech Recognition
try:
    print("Você disse: " + r.recognize_google(audio))
except sr.UnknownValueError ue:
    print("Houve um erro: {0}".format(ue))
except sr.RequestError as e:
    print("Falha na requisição ao serviço Google Speech Recognition: {0}".format(e))
  • I’ve already implemented the speech_recognition as sr. I just want the program to run when I say "OK Google" for example. As if I "call" the program to open when I speak.

  • More there you have to configure in the operating system. If it’s Windows you have to set up Cortana, if it’s Linux you have to set up Sirius, if it’s Macos you have to set up Siri and if it’s Android it’s Android Assistent. It has nothing to do with Python.

  • In python you create a service to use the Listener listen_in_background(source, callback).

Browser other questions tagged

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