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))
You have come to implement some code?
– RXSD
To do so use an API speech recognition
– Augusto Vasques