Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # NOTE: this example requires PyAudio because it uses the Microphone class
- # partly developed my me, David Beck www.dwbeck.com
- import speech_recognition as sr
- import webbrowser
- from msvcrt import getch
- from time import sleep, strftime
- #keypress handler
- while True:
- key = ord(getch())
- print(key)
- sleep(0.1)
- if key == 27: #ESC
- print('SUP NIGGA')
- # obtain audio from the microphone
- class run_voice_recog():
- def __init__(self):
- pass
- def recognizer():
- r = sr.Recognizer()
- with sr.Microphone() as source:
- print("Say something!")
- audio = r.listen(source)
- # recognize speech using Google Speech Recognition
- try:
- # for testing purposes, we're just using the default API key
- # to use another API key, use `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")`
- # instead of `r.recognize_google(audio)`
- google_response = r.recognize_google(audio)
- print("Google Speech Recognition thinks you said " + google_response)
- if 'yahoo' in google_response:
- print('Going to your Yahoo')
- webbrowser.open_new_tab('https://mail.yahoo.com/')
- elif 'email' in google_response:
- print('Going to your email')
- webbrowser.open_new_tab('https://www.mailindeed.com/roundcube/')
- elif 'Facebook' in google_response:
- print('Going to your Facebook')
- webbrowser.open_new_tab('https://www.facebook.com/')
- elif 'website' in google_response and 'my' in google_response:
- print('Going to your website')
- webbrowser.open_new_tab('www.dwbeck.com')
- except sr.UnknownValueError:
- print("Google Speech Recognition could not understand audio")
- except sr.RequestError as e:
- print("Could not request results from Google Speech Recognition service; {0}".format(e))
- run_voice_recog.recognizer()
- ### recognize speech using Google Cloud Speech
- ##GOOGLE_CLOUD_SPEECH_CREDENTIALS = r"""INSERT THE CONTENTS OF THE GOOGLE CLOUD SPEECH JSON CREDENTIALS FILE HERE"""
- ##try:
- ## print("Google Cloud Speech thinks you said " + r.recognize_google_cloud(audio, credentials_json=GOOGLE_CLOUD_SPEECH_CREDENTIALS))
- ##except sr.UnknownValueError:
- ## print("Google Cloud Speech could not understand audio")
- ##except sr.RequestError as e:
- ## print("Could not request results from Google Cloud Speech service; {0}".format(e))
- ### recognize speech using Wit.ai
- ##WIT_AI_KEY = "INSERT WIT.AI API KEY HERE" # Wit.ai keys are 32-character uppercase alphanumeric strings
- ##try:
- ## print("Wit.ai thinks you said " + r.recognize_wit(audio, key=WIT_AI_KEY))
- ##except sr.UnknownValueError:
- ## print("Wit.ai could not understand audio")
- ##except sr.RequestError as e:
- ## print("Could not request results from Wit.ai service; {0}".format(e))
- ##
- ### recognize speech using Microsoft Bing Voice Recognition
- ##BING_KEY = "INSERT BING API KEY HERE" # Microsoft Bing Voice Recognition API keys 32-character lowercase hexadecimal strings
- ##try:
- ## print("Microsoft Bing Voice Recognition thinks you said " + r.recognize_bing(audio, key=BING_KEY))
- ##except sr.UnknownValueError:
- ## print("Microsoft Bing Voice Recognition could not understand audio")
- ##except sr.RequestError as e:
- ## print("Could not request results from Microsoft Bing Voice Recognition service; {0}".format(e))
- ##
- ### recognize speech using Houndify
- ##HOUNDIFY_CLIENT_ID = "INSERT HOUNDIFY CLIENT ID HERE" # Houndify client IDs are Base64-encoded strings
- ##HOUNDIFY_CLIENT_KEY = "INSERT HOUNDIFY CLIENT KEY HERE" # Houndify client keys are Base64-encoded strings
- ##try:
- ## print("Houndify thinks you said " + r.recognize_houndify(audio, client_id=HOUNDIFY_CLIENT_ID, client_key=HOUNDIFY_CLIENT_KEY))
- ##except sr.UnknownValueError:
- ## print("Houndify could not understand audio")
- ##except sr.RequestError as e:
- ## print("Could not request results from Houndify service; {0}".format(e))
- ##
- ### recognize speech using IBM Speech to Text
- ##IBM_USERNAME = "INSERT IBM SPEECH TO TEXT USERNAME HERE" # IBM Speech to Text usernames are strings of the form XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
- ##IBM_PASSWORD = "INSERT IBM SPEECH TO TEXT PASSWORD HERE" # IBM Speech to Text passwords are mixed-case alphanumeric strings
- ##try:
- ## print("IBM Speech to Text thinks you said " + r.recognize_ibm(audio, username=IBM_USERNAME, password=IBM_PASSWORD))
- ##except sr.UnknownValueError:
- ## print("IBM Speech to Text could not understand audio")
- ##except sr.RequestError as e:
- ## print("Could not request results from IBM Speech to Text service; {0}".format(e))
- ##
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement