Advertisement
Guest User

Untitled

a guest
Mar 16th, 2018
2,479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.83 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. # NOTE: this example requires PyAudio because it uses the Microphone class
  4.  
  5. # partly developed my me, David Beck www.dwbeck.com
  6.  
  7. import speech_recognition as sr
  8. import webbrowser
  9. from msvcrt import getch
  10. from time import sleep, strftime
  11. #keypress handler
  12.  
  13. while True:
  14.     key = ord(getch())
  15.     print(key)
  16.     sleep(0.1)
  17.    
  18.     if key == 27: #ESC
  19.        
  20.        
  21.         print('SUP NIGGA')
  22.  
  23. # obtain audio from the microphone
  24. class run_voice_recog():
  25.  
  26.     def __init__(self):
  27.         pass
  28.  
  29.     def recognizer():
  30.         r = sr.Recognizer()
  31.         with sr.Microphone() as source:
  32.             print("Say something!")
  33.             audio = r.listen(source)
  34.  
  35.         # recognize speech using Google Speech Recognition
  36.         try:
  37.             # for testing purposes, we're just using the default API key
  38.             # to use another API key, use `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")`
  39.             # instead of `r.recognize_google(audio)`
  40.             google_response = r.recognize_google(audio)
  41.             print("Google Speech Recognition thinks you said " + google_response)
  42.             if 'yahoo' in google_response:
  43.                 print('Going to your Yahoo')
  44.                 webbrowser.open_new_tab('https://mail.yahoo.com/')
  45.             elif 'email' in google_response:
  46.                 print('Going to your email')
  47.                 webbrowser.open_new_tab('https://www.mailindeed.com/roundcube/')
  48.             elif 'Facebook' in google_response:
  49.                 print('Going to your Facebook')
  50.                 webbrowser.open_new_tab('https://www.facebook.com/')
  51.             elif 'website' in google_response and 'my' in google_response:
  52.                 print('Going to your website')
  53.                 webbrowser.open_new_tab('www.dwbeck.com')
  54.  
  55.            
  56.         except sr.UnknownValueError:
  57.             print("Google Speech Recognition could not understand audio")
  58.         except sr.RequestError as e:
  59.             print("Could not request results from Google Speech Recognition service; {0}".format(e))
  60.  
  61.  
  62. run_voice_recog.recognizer()
  63.  
  64.  
  65. ### recognize speech using Google Cloud Speech
  66. ##GOOGLE_CLOUD_SPEECH_CREDENTIALS = r"""INSERT THE CONTENTS OF THE GOOGLE CLOUD SPEECH JSON CREDENTIALS FILE HERE"""
  67. ##try:
  68. ##    print("Google Cloud Speech thinks you said " + r.recognize_google_cloud(audio, credentials_json=GOOGLE_CLOUD_SPEECH_CREDENTIALS))
  69. ##except sr.UnknownValueError:
  70. ##    print("Google Cloud Speech could not understand audio")
  71. ##except sr.RequestError as e:
  72. ##    print("Could not request results from Google Cloud Speech service; {0}".format(e))
  73.  
  74. ### recognize speech using Wit.ai
  75. ##WIT_AI_KEY = "INSERT WIT.AI API KEY HERE"  # Wit.ai keys are 32-character uppercase alphanumeric strings
  76. ##try:
  77. ##    print("Wit.ai thinks you said " + r.recognize_wit(audio, key=WIT_AI_KEY))
  78. ##except sr.UnknownValueError:
  79. ##    print("Wit.ai could not understand audio")
  80. ##except sr.RequestError as e:
  81. ##    print("Could not request results from Wit.ai service; {0}".format(e))
  82. ##
  83. ### recognize speech using Microsoft Bing Voice Recognition
  84. ##BING_KEY = "INSERT BING API KEY HERE"  # Microsoft Bing Voice Recognition API keys 32-character lowercase hexadecimal strings
  85. ##try:    
  86. ##    print("Microsoft Bing Voice Recognition thinks you said " + r.recognize_bing(audio, key=BING_KEY))
  87. ##except sr.UnknownValueError:
  88. ##    print("Microsoft Bing Voice Recognition could not understand audio")
  89. ##except sr.RequestError as e:
  90. ##    print("Could not request results from Microsoft Bing Voice Recognition service; {0}".format(e))
  91. ##
  92. ### recognize speech using Houndify
  93. ##HOUNDIFY_CLIENT_ID = "INSERT HOUNDIFY CLIENT ID HERE"  # Houndify client IDs are Base64-encoded strings
  94. ##HOUNDIFY_CLIENT_KEY = "INSERT HOUNDIFY CLIENT KEY HERE"  # Houndify client keys are Base64-encoded strings
  95. ##try:
  96. ##    print("Houndify thinks you said " + r.recognize_houndify(audio, client_id=HOUNDIFY_CLIENT_ID, client_key=HOUNDIFY_CLIENT_KEY))
  97. ##except sr.UnknownValueError:
  98. ##    print("Houndify could not understand audio")
  99. ##except sr.RequestError as e:
  100. ##    print("Could not request results from Houndify service; {0}".format(e))
  101. ##
  102. ### recognize speech using IBM Speech to Text
  103. ##IBM_USERNAME = "INSERT IBM SPEECH TO TEXT USERNAME HERE"  # IBM Speech to Text usernames are strings of the form XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
  104. ##IBM_PASSWORD = "INSERT IBM SPEECH TO TEXT PASSWORD HERE"  # IBM Speech to Text passwords are mixed-case alphanumeric strings
  105. ##try:
  106. ##    print("IBM Speech to Text thinks you said " + r.recognize_ibm(audio, username=IBM_USERNAME, password=IBM_PASSWORD))
  107. ##except sr.UnknownValueError:
  108. ##    print("IBM Speech to Text could not understand audio")
  109. ##except sr.RequestError as e:
  110. ##    print("Could not request results from IBM Speech to Text service; {0}".format(e))
  111. ##
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement