forked from ecthros/uncaptcha2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
queryAPI.py
61 lines (53 loc) · 2.05 KB
/
queryAPI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import speech_recognition as sr
global r
r = sr.Recognizer()
#################### SPEECH-TO-TEXT WEB APIS ####################
###### The following functions interact with the APIs we used to query for each segment ########
###### Keys have been removed from this section #######
#Query Wit
def wit(audio):
# recognize speech using Wit.ai
WIT_AI_KEY = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx" # Wit.ai keys are 32-character uppercase alphanumeric strings
try:
#print("Wit.ai: ")
return r.recognize_wit(audio, key=WIT_AI_KEY)
except sr.UnknownValueError:
print("Wit.ai could not understand audio")
return "None"
except sr.RequestError as e:
print("Could not request results from Wit.ai service; {0}".format(e))
return "None"
def bing(audio):
BING_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# recognize speech using Microsoft Bing Voice Recognition
try:
#print("Microsoft Bing Voice Recognition: ")
return r.recognize_bing(audio, key=BING_KEY)
except sr.UnknownValueError:
print("Microsoft Bing Voice Recognition could not understand audio")
return "None"
except sr.RequestError as e:
print("Could not request results from Microsoft Bing Voice Recognition service; {0}".format(e))
return "None"
# Query IBM
def ibm(audio):
# recognize speech using IBM Speech to Text
IBM_USERNAME = "xxxxxxxxxxxxxxxxxxxxxxxxxx" # IBM Speech to Text usernames are strings of the form XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
IBM_PASSWORD = "xxxxxxxxxxxxxxxxx" # IBM Speech to Text passwords are mixed-case alphanumeric strings
try:
#print("IBM Speech to Text: ")
return r.recognize_ibm(audio, username=IBM_USERNAME, password=IBM_PASSWORD, show_all=False)
except sr.UnknownValueError:
print("IBM Speech to Text could not understand audio")
return "None"
except sr.RequestError as e:
print("Could not request results from IBM Speech to Text service; {0}".format(e))
return "None"
#Query Google Speech-To-Text
def google(audio):
try:
#print("Google: ")
return r.recognize_google(audio)
except:
print("Google could not understand")
return "None"