Closed DarKWinGTM closed 7 years ago
Hi @DarKWinGTM,
I'm afraid I don't understand the first issue in your description - would you mind filling in the issue template? Please feel free to re-open this afterwards!
As for checking credit, I don't think Houndify exposes that information, besides as an error when you don't have enough of them.
Sorry for first issue i made you confuse
i mean sr. request to any account on Houndify and that account not enough credit sr. not send any error code like "UnknownValueError,RequestError" for pass to except
i will show source now am using on mobile
when request to account without credit it's freeze
It should give an error rather than freezing - do you have a working code example that exhibits the freezing issue?
I not show any message or feedback any info
# VERSION 0.6
# INSTALLPYTHONMODULE
# pip install appdirs==1.4.3
# pip install Cerberus==0.9.2
# pip install click==6.7
# pip install Cython==0.25.2
# pip install Eve==0.7.2
# pip install Events==0.2.2
# pip install Flask==0.10.1
# pip install Flask-PyMongo==0.4.1
# pip install flax==0.2.5
# pip install get==0.0.0
# pip install heroku==0.1.4
# pip install itsdangerous==0.24
# pip install Jinja2==2.9.5
# pip install MarkupSafe==0.23
# pip install packaging==16.8
# pip install pocketsphinx==0.1.3
# pip install post==0.0.0
# pip install public==0.0.0
# pip install PyAudio==0.2.11
# pip install pydub==0.18.0
# pip install pymongo==3.4.0
# pip install pyparsing==2.2.0
# pip install python-dateutil==1.5
# pip install query-string==0.0.0
# pip install request==0.0.0
# pip install requests==2.13.0
# pip install selenium==3.3.1
# pip install setupfiles==0.0.0
# pip install simplejson==3.10.0
# pip install six==1.10.0
# pip install SpeechRecognition==3.6.3
# pip install SQLAlchemy==1.1.6
# pip install virtualenv==15.1.0
# pip install Werkzeug==0.11.15
# pip install wget==3.2
import os
import re
import ssl
import glob
import wget
import time
import base64
import signal
import random
import urllib
import shutil
import datetime
import requests
import speech_recognition
from pydub import AudioSegment as audioseg
from pydub.silence import split_on_silence as splitonsilence
from flask import Flask, request
app = Flask(__name__)
@app.route("/")
def index():
return '<form action="/echo" method="GET"><input name="text"><input type="submit" value="Echo"></form>'
@app.route("/echo")
def echo():
return "You said: " + request.args.get('text', '')
''' Read/Encode audio files to Base64 text
@app.route("/encode")
def encode():
WEB = request.args.get("web", "") #NOTICES : GET CURRENT WEB NAME
URL = request.args.get("url", "") #NOTICES : GET URL
API = request.args.get("k", "") #NOTICES : GET API KEY
REQ = ((URL) + '&k=' +(API)) #NOTICES : SET URL
audiomp3 = ((WEB) + '.mp3') #NOTICES : SET STRING AND FORMAT
audiowav = ((WEB) + '.wav') #NOTICES : SET STRING AND FORMAT
audiospl = ((WEB) + '{0}.wav') #NOTICES : SET STRING AND FORMAT
urllib.request.urlretrieve(REQ, audiomp3) #NOTICES : DOWNLOAD FROM URL
audioseg.from_mp3(audiomp3).export(audiowav, format="wav") #NOTICES : EXPORT/CONVERT MP3 TO WAV
time.sleep(1) #NOTICES : ENCODE FILE TO BASE64
enc = base64.encodestring(open(audiowav, 'rb').read()) #NOTICES : LOG HISTORY BASE64
return ("ENCOED : " + (enc))
'''
@app.route("/captcha")
def captcha():
WEB = request.args.get("web", "") #NOTICES : GET CURRENT WEB NAME
URL = request.args.get("url", "") #NOTICES : GET URL
API = request.args.get("k", "") #NOTICES : GET API KEY
REQ = ((URL) + '&k=' +(API)) #NOTICES : SET URL
audiomp3 = ((WEB) + '.mp3') #NOTICES : SET STRING AND FORMAT
audiowav = ((WEB) + '.wav') #NOTICES : SET STRING AND FORMAT
audiospl = ((WEB) + '{0}.wav') #NOTICES : SET STRING AND FORMAT
usage = (random.choice(['h','he','ha','hb','hc','hd'])) #NOTICES : RANDOM SERVICE
kword = ['your computer or network', 'your computer network', 'sending automated queries', 'Error', 'error'] #NOTICES : FIX KEYWORD
urllib.request.urlretrieve(REQ, audiomp3) #NOTICES : DOWNLOAD FROM URL
audioseg.from_mp3(audiomp3).export(audiowav, format="wav") #NOTICES : EXPORT/CONVERT MP3 TO WAV
'''
for i, chunk in enumerate(splitonsilence(audioseg.from_wav(audiowav), min_silence_len=250, silence_thresh=-30, keep_silence=500)): #NOTICES : SPLIT AUDIO
out_file = ".//splitAudio//" + (audiospl).format(i) #NOTICES : SPLIT AUDIO
print ("Exporting : ",out_file) #NOTICES : SPLIT AUDIO
chunk.export(out_file, format="wav") #NOTICES : SPLIT AUDIO
with speech_recognition.Microphone() as source: #NOTICES : USE THE DEFAULT MICROPHONE AS THE AUDIO SOURCE, LISTEN FOR 1 SECOND TO CALIBRATE THE ENERGY THRESHOLD FOR AMBIENT NOISE LEVELS
speech_recognition.Recognizer().adjust_for_ambient_noise(source) #NOTICES : USE THE DEFAULT MICROPHONE AS THE AUDIO SOURCE, LISTEN FOR 1 SECOND TO CALIBRATE THE ENERGY THRESHOLD FOR AMBIENT NOISE LEVELS
'''
time.sleep(1)
with speech_recognition.WavFile(audiowav) as source:
#DISABLE audio = speech_recognition.Recognizer().record.adjust_for_ambient_noise(source) #NOTICES : AUDIO WITH REMOVE AMBIENT NOISE
audio = speech_recognition.Recognizer().record(source)
try:
print("SPEECH RECEIVED")
#DISABLE value = speech_recognition.Recognizer().recognize_google(audio, language = "en-in").replace("'", " ")
#DISABLE print("Speech Pending : " + (value))
value = speech_recognition.Recognizer().recognize_sphinx(audio)
print("SPHINX PENDING : " + (value))
except speech_recognition.UnknownValueError:
value = ('Error : Speech Recognition (UnknownValueError)')
print("SPEECH RECOGNITION UNKNOWN VALUE ERROR")
return value
except speech_recognition.RequestError as e:
value = ('Error : Speech Recognition (RequestError)')
print("COULD NOT REQUEST FROM SPEECH RECOGNITION SERVICE; {0}".format(e))
return value
if not any(word in value for word in kword):
print("SUBMITED : " + (usage))
if (usage) is 'g':
try:
value = speech_recognition.Recognizer().recognize_google(audio, language = "en-in") #NOTICES : TO USE ANOTHER API KEY, USE `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")`
if str is bytes:
result = u"{}".format(value).encode("utf-8")
else:
result = "{}".format(value)
with open("audio.log","w") as f:
f.write("Google Speech Recognition :" + (result))
with open("audio.his","a") as f:
f.write("\nGoogle Speech Recognition :" + (result) + ']' + ' HISTORY : ' + (audiomp3))
print("Google Speech Recognition : " + (value))
print("Completed")
return value
except speech_recognition.UnknownValueError:
print("Google Speech Recognition Unknown Value Error")
value = ('Error : ' + (e))
except speech_recognition.RequestError as e:
print("Could not request from Google Speech Recognition service; {0}".format(e))
value = ('Error : ' + (e))
else:
pass
if (usage) is 'w':
try:
value = speech_recognition.Recognizer().recognize_wit(audio, key ="") #NOTICES : https://wit.ai/DarKWinGTM/MyFirstApp/settings
if str is bytes:
result = u"{}".format(value).encode("utf-8")
else:
result = "{}".format(value)
with open("audio.log","w") as f:
f.write("WIT.AI : " + (result))
with open("audio.his","a") as f:
f.write("\nWIT.AI : " + (result) + ']' + ' HISTORY : ' + (audiomp3))
print("WIT.AI : " + (value))
print("Completed")
return value
except speech_recognition.UnknownValueError:
print("WIT.AI Unknown Value Error")
value = ('Error : ' + (e))
except speech_recognition.RequestError as e:
print("Could not request from WIT.AI service; {0}".format(e))
value = ('Error : ' + (e))
else:
pass
if (usage) is 'm':
try:
value = speech_recognition.Recognizer().recognize_ibm(audio, key = "") #NOTICES : https://www.microsoft.com/cognitive-services/en-US/subscriptions
if str is bytes:
result = u"{}".format(value).encode("utf-8")
else:
result = "{}".format(value)
with open("audio.log","w") as f:
f.write("Bring : " + (result))
with open("audio.his","a") as f:
f.write("\nBring : " + (result) + ']' + ' HISTORY : ' + (audiomp3))
print("Bring : " + (value))
print("Completed")
return value
except speech_recognition.UnknownValueError:
print("Bring Unknown Value Error")
value = ('Error : ' + (e))
except speech_recognition.RequestError as e:
print("Could not request from Bring service; {0}".format(e))
value = ('Error : ' + (e))
else:
pass
if (usage) is 'ibm':
try:
value = speech_recognition.Recognizer().recognize_ibm(audio, username="", password="" ) #NOTICES : https://www.microsoft.com/cognitive-services/en-US/subscriptions
if str is bytes:
result = u"{}".format(value).encode("utf-8")
else:
result = "{}".format(value)
with open("audio.log","w") as f:
f.write("IBM : " + (result))
with open("audio.his","a") as f:
f.write("\nIBM : " + (result) + ']' + ' HISTORY : ' + (audiomp3))
print("IBM : " + (value))
print("Completed")
return value
except speech_recognition.UnknownValueError:
print("IBM Unknown Value Error")
value = ('Error : ' + (e))
except speech_recognition.RequestError as e:
print("Could not request from IBM service; {0}".format(e))
value = ('Error : ' + (e))
else:
pass
if (usage) is 'h' or 'he' or 'ha' or 'hb' or 'hc' or 'hd':
maxRusage = 0.0
sendusage = 'load'
while (maxRusage) < 5.0 and (sendusage) is not 'done':
try:
keyusage = int(random.randint(0,30))
apikey = open('Z:/GitHub/reCaptcha/apikey.key', 'r').readlines()
HOUNDIFY_CLIENT_ID,HOUNDIFY_CLIENT_KEY,MAIL = apikey[keyusage].split(',')
creditcur = int(open(r"audio.ser", "r", encoding="utf-8-sig").read().count('[{0}]'.format(int(datetime.datetime.now().strftime("%Y%m%d"))-0) + '[{:0>5d}]'.format(keyusage)))
creditpre = int(open(r"audio.ser", "r", encoding="utf-8-sig").read().count('[{0}]'.format(int(datetime.datetime.now().strftime("%Y%m%d"))-1) + '[{:0>5d}]'.format(keyusage)))
if (creditcur) < 24 and (creditpre) < 24:
maxRusage += 1.0
pass
else:
maxRusage += 0.2
continue
'''
elif (creditcur) < 24 and (creditcur + creditpre) < 44:
maxRusage += 1.0
pass
elif (creditcur) < 24 and (creditcur + creditpre) > 44:
maxRusage += 0.2
continue
elif (creditcur) > 24 and (creditcur + creditpre) < 44:
maxRusage += 1.0
pass
elif (creditcur) > 24 and (creditcur + creditpre) > 44:
maxRusage += 0.2
continue
'''
print("HOUNDIFY ID : " + (HOUNDIFY_CLIENT_ID))
print("HOUNDIFY PW : " + (HOUNDIFY_CLIENT_KEY))
print("HOUNDIFY CLIENT : " + '[{0}]'.format(maxRusage) + '[{0}]'.format(sendusage) + '[{0}]'.format(usage) + '[{:0>5d}]'.format(keyusage))
print("HOUNDIFY CREDIT : " + '[{0}]'.format(creditcur) + '[{0}]'.format(creditpre))
value = speech_recognition.Recognizer().recognize_houndify(audio, client_id=HOUNDIFY_CLIENT_ID, client_key=HOUNDIFY_CLIENT_KEY)
if str is bytes:
result = u"{}".format(value).encode("utf-8")
else:
result = "{}".format(value)
with open("audio.log","w") as f:
f.write("Houndify : " + (result))
with open("audio.his","a") as f:
f.write("\nHoundify : " + (audiomp3) + ' ' + '[{0}]'.format(datetime.datetime.now().strftime("%Y%m%d")) + '[{:0>5d}]'.format(keyusage) + ' ' + (result))
sendusage = 'done'
print("HOUNDIFY OUTPUT : " + (value) + ' ' + '[{:0>5d}]'.format(keyusage))
return value
except speech_recognition.UnknownValueError:
value = ('Error : Houndify (UnknownValueError)')
print("HOUNDIFY UNKNOWN VALUE ERROR : "+ '[{:0>5d}]'.format(keyusage))
continue
except speech_recognition.RequestError as e:
value = ('Error : Houndify (RequestError)')
print("COULD NOT REQUEST FROM HOUNDIFY SERVICE; {0}".format(e) + '[{:0>5d}]'.format(keyusage))
continue
'''
if maxRusage > 5.0 or maxRusage = 5.0:
value = 'Error : '
'''
else:
pass
else:
print("REJECTED")
return value
if __name__ == "__main__":
'''
os.system("start \"\" http://127.0.0.1:5000/captcha?url=Welcome")
'''
app.run(host="127.0.0.2", port=5000, threaded=True)
app.run(processes=8)
Hi @DarKWinGTM,
First, you probably want to revoke those API keys as soon as possible - you especially wouldn't want those IBM credentials to be stolen.
I can't seem to reproduce this issue, unfortunately - is there anything unusual with your network? Do the other speech engines like IBM and Wit.ai work correctly?
Does the program print anything at all for you? If so, can you post the entire output of a program run?
Maybe try setting the show_all
parameter of recognize_houndify
to True
- it'll help debug the output result.
Other service don't have credit limite , i don't have problem with other service ibm,wit.ai working fine and houndify too but it have problem only when credit is over 100 and trying request on these account . i will try config show_all to true
It's not help if i set "show_all=true" it's not send or show any error code for switch to except when error if i request to credit limit account , maybe houndify not send anything back and block if you request to credit limit account
Maybe i will try to write python to check email if recieve alert email from houndify when "reached daily credit limit"
it's not send or show any error code for switch to except when error if i request to credit limit account
So it did return a response then? It sounds like it would be possible to catch that error as a recognizer failure.
It's not return any response , When request to these account no error code return no result back no recognizer failure back for match condition except , the module request with unstop and without response because no response error back, it's cause not swithch to match with condition except
Okay, so if I'm understanding correctly, the script is hanging when it tries to make a request?
I can't really reproduce this unfortunately (for me it gives a RequestError when I run out of credits). What output does the audio_transcribe example give if you run it in the terminal, and then press Ctrl + C in the terminal when it hangs?
If the traceback shows the urlopen line, try replacing value = speech_recognition.Recognizer().recognize_houndify(audio, client_id=HOUNDIFY_CLIENT_ID, client_key=HOUNDIFY_CLIENT_KEY)
with the following code:
r = speech_recognition.Recognizer()
r.operation_timeout = 5 # seconds until timeout
value = r.recognize_houndify(audio, client_id=HOUNDIFY_CLIENT_ID, client_key=HOUNDIFY_CLIENT_KEY)
r.operation_timeout = 5 # seconds until timeout
Maybe it help to pass when request to empty credit account ,I will try
If i write like this it correct ?
value = speech_recognition.Recognizer().operation_timeout(5).recognize_houndify(audio, client_id=HOUNDIFY_CLIENT_ID, client_key=HOUNDIFY_CLIENT_KEY) or value = speech_recognition.Recognizer().operation_timeout = 5.recognize_houndify(audio, client_id=HOUNDIFY_CLIENT_ID, client_key=HOUNDIFY_CLIENT_KEY) or speech_recognition.Recognizer().operation_timeout = 5 value = speech_recognition.Recognizer().recognize_houndify(audio, client_id=HOUNDIFY_CLIENT_ID, client_key=HOUNDIFY_CLIENT_KEY)
Sorry if disturb your time. Thanks , Best regard
Okay it fixed it thing something is worng if not import speech_recognition as sr and set r = sr.Recognizer() , maybe except feed back is not match, but known it's okay if set it back to 'r.' and sr.
I'm not sure what that means, but glad to hear it is working now!
This source is fixed
Can you explain about why can't remove "sr." and replace to "speech_recognition." and remove "r." and replace with "speech_recognition.Recognizer()." ?
# VERSION 0.8
# INSTALLPYTHONMODULE
# pip install appdirs==1.4.3
# pip install Cerberus==0.9.2
# pip install click==6.7
# pip install Cython==0.25.2
# pip install Eve==0.7.2
# pip install Events==0.2.2
# pip install Flask==0.10.1
# pip install Flask-PyMongo==0.4.1
# pip install flax==0.2.5
# pip install get==0.0.0
# pip install heroku==0.1.4
# pip install itsdangerous==0.24
# pip install Jinja2==2.9.5
# pip install MarkupSafe==0.23
# pip install packaging==16.8
# pip install pocketsphinx==0.1.3
# pip install post==0.0.0
# pip install public==0.0.0
# pip install PyAudio==0.2.11
# pip install pydub==0.18.0
# pip install pymongo==3.4.0
# pip install pyparsing==2.2.0
# pip install python-dateutil==1.5
# pip install query-string==0.0.0
# pip install request==0.0.0
# pip install requests==2.13.0
# pip install selenium==3.3.1
# pip install setupfiles==0.0.0
# pip install simplejson==3.10.0
# pip install six==1.10.0
# pip install SpeechRecognition==3.6.3
# pip install SQLAlchemy==1.1.6
# pip install virtualenv==15.1.0
# pip install Werkzeug==0.11.15
# pip install wget==3.2
import os
import re
import ssl
import glob
import wget
import time
import base64
import signal
import random
import urllib
import shutil
import datetime
import requests
import speech_recognition as sr
from pydub import AudioSegment as audioseg
from pydub.silence import split_on_silence as splitonsilence
from flask import Flask, request
app = Flask(__name__)
@app.route("/")
def index():
return '<form action="/echo" method="GET"><input name="text"><input type="submit" value="Echo"></form>'
@app.route("/echo")
def echo():
return "You said: " + request.args.get('text', '')
''' Read/Encode audio files to Base64 text
@app.route("/encode")
def encode():
WEB = request.args.get("web", "") #NOTICES : GET CURRENT WEB NAME
URL = request.args.get("url", "") #NOTICES : GET URL
API = request.args.get("k", "") #NOTICES : GET API KEY
REQ = ((URL) + '&k=' +(API)) #NOTICES : SET URL
audiomp3 = ((WEB) + '.mp3') #NOTICES : SET STRING AND FORMAT
audiowav = ((WEB) + '.wav') #NOTICES : SET STRING AND FORMAT
audiospl = ((WEB) + '{0}.wav') #NOTICES : SET STRING AND FORMAT
urllib.request.urlretrieve(REQ, audiomp3) #NOTICES : DOWNLOAD FROM URL
audioseg.from_mp3(audiomp3).export(audiowav, format="wav") #NOTICES : EXPORT/CONVERT MP3 TO WAV
time.sleep(1) #NOTICES : ENCODE FILE TO BASE64
enc = base64.encodestring(open(audiowav, 'rb').read()) #NOTICES : LOG HISTORY BASE64
return ("ENCOED : " + (enc))
'''
@app.route("/captcha")
def captcha():
WEB = request.args.get("web", "") #NOTICES : GET CURRENT WEB NAME
URL = request.args.get("url", "") #NOTICES : GET URL
API = request.args.get("k", "") #NOTICES : GET API KEY
REQ = ((URL) + '&k=' +(API)) #NOTICES : SET URL
audiomp3 = ((WEB) + '.mp3') #NOTICES : SET STRING AND FORMAT
audiowav = ((WEB) + '.wav') #NOTICES : SET STRING AND FORMAT
audiospl = ((WEB) + '{0}.wav') #NOTICES : SET STRING AND FORMAT
usage = (random.choice(['h','he','ha','hb','hc','hd'])) #NOTICES : RANDOM SERVICE
kword = ['your computer or network', 'your computer network', 'sending automated queries', 'Error', 'error'] #NOTICES : FIX KEYWORD
urllib.request.urlretrieve(REQ, audiomp3) #NOTICES : DOWNLOAD FROM URL
audioseg.from_mp3(audiomp3).export(audiowav, format="wav") #NOTICES : EXPORT/CONVERT MP3 TO WAV
'''
for i, chunk in enumerate(splitonsilence(audioseg.from_wav(audiowav), min_silence_len=250, silence_thresh=-30, keep_silence=500)): #NOTICES : SPLIT AUDIO
out_file = ".//splitAudio//" + (audiospl).format(i) #NOTICES : SPLIT AUDIO
print ("Exporting : ",out_file) #NOTICES : SPLIT AUDIO
chunk.export(out_file, format="wav") #NOTICES : SPLIT AUDIO
with sr.Microphone() as source: #NOTICES : USE THE DEFAULT MICROPHONE AS THE AUDIO SOURCE, LISTEN FOR 1 SECOND TO CALIBRATE THE ENERGY THRESHOLD FOR AMBIENT NOISE LEVELS
r.adjust_for_ambient_noise(source) #NOTICES : USE THE DEFAULT MICROPHONE AS THE AUDIO SOURCE, LISTEN FOR 1 SECOND TO CALIBRATE THE ENERGY THRESHOLD FOR AMBIENT NOISE LEVELS
'''
time.sleep(1)
r = sr.Recognizer()
with sr.WavFile(audiowav) as source:
#DISABLE audio = r.record.adjust_for_ambient_noise(source) #NOTICES : AUDIO WITH REMOVE AMBIENT NOISE
audio = r.record(source)
try:
print("SPEECH RECEIVED")
#DISABLE value = r.recognize_google(audio, language = "en-in").replace("'", " ")
#DISABLE print("Speech Pending : " + (value))
value = r.recognize_sphinx(audio)
print("SPHINX PENDING : " + (value))
except sr.UnknownValueError:
value = ('Error : Speech Recognition (UnknownValueError)')
print("SPEECH RECOGNITION UNKNOWN VALUE ERROR")
return value
except sr.RequestError as e:
value = ('Error : Speech Recognition (RequestError)')
print("COULD NOT REQUEST FROM SPEECH RECOGNITION SERVICE; {0}".format(e))
return value
if not any(word in value for word in kword):
print("SUBMITED : " + (usage))
if (usage) is 'g':
try:
value = r.recognize_google(audio, language = "en-in") #NOTICES : TO USE ANOTHER API KEY, USE `r.recognize_google(audio, key="GOOGLE_sr_API_KEY")`
if str is bytes:
result = u"{}".format(value).encode("utf-8")
else:
result = "{}".format(value)
with open("audio.log","w") as f:
f.write("Google Speech Recognition :" + (result))
with open("audio.his","a") as f:
f.write("\nGoogle Speech Recognition :" + (result) + ']' + ' HISTORY : ' + (audiomp3))
print("Google Speech Recognition : " + (value))
print("Completed")
return value
except sr.UnknownValueError:
print("Google Speech Recognition Unknown Value Error")
value = ('Error : ' + (e))
except sr.RequestError as e:
print("Could not request from Google Speech Recognition service; {0}".format(e))
value = ('Error : ' + (e))
else:
pass
if (usage) is 'w':
try:
value = r.recognize_wit(audio, key = "xxx") #NOTICES : https://wit.ai/DarKWinGTM/MyFirstApp/settings
if str is bytes:
result = u"{}".format(value).encode("utf-8")
else:
result = "{}".format(value)
with open("audio.log","w") as f:
f.write("WIT.AI : " + (result))
with open("audio.his","a") as f:
f.write("\nWIT.AI : " + (result) + ']' + ' HISTORY : ' + (audiomp3))
print("WIT.AI : " + (value))
print("Completed")
return value
except sr.UnknownValueError:
print("WIT.AI Unknown Value Error")
value = ('Error : ' + (e))
except sr.RequestError as e:
print("Could not request from WIT.AI service; {0}".format(e))
value = ('Error : ' + (e))
else:
pass
if (usage) is 'm':
try:
value = r.recognize_ibm(audio, key = "xxx") #NOTICES : https://www.microsoft.com/cognitive-services/en-US/subscriptions
if str is bytes:
result = u"{}".format(value).encode("utf-8")
else:
result = "{}".format(value)
with open("audio.log","w") as f:
f.write("Bring : " + (result))
with open("audio.his","a") as f:
f.write("\nBring : " + (result) + ']' + ' HISTORY : ' + (audiomp3))
print("Bring : " + (value))
print("Completed")
return value
except sr.UnknownValueError:
print("Bring Unknown Value Error")
value = ('Error : ' + (e))
except sr.RequestError as e:
print("Could not request from Bring service; {0}".format(e))
value = ('Error : ' + (e))
else:
pass
if (usage) is 'ibm':
try:
value = r.recognize_ibm(audio, username="414cbf5e-dfd1-432a-9cb5-74f73da86e30", password="xxx" ) #NOTICES : https://www.microsoft.com/cognitive-services/en-US/subscriptions
if str is bytes:
result = u"{}".format(value).encode("utf-8")
else:
result = "{}".format(value)
with open("audio.log","w") as f:
f.write("IBM : " + (result))
with open("audio.his","a") as f:
f.write("\nIBM : " + (result) + ']' + ' HISTORY : ' + (audiomp3))
print("IBM : " + (value))
print("Completed")
return value
except sr.UnknownValueError:
print("IBM Unknown Value Error")
value = ('Error : ' + (e))
except sr.RequestError as e:
print("Could not request from IBM service; {0}".format(e))
value = ('Error : ' + (e))
else:
pass
if (usage) is 'h' or 'he' or 'ha' or 'hb' or 'hc' or 'hd':
maxRusage = 0.0
sendusage = 'load'
while (maxRusage) < 5.0 and (sendusage) is not 'done':
try:
apikey = open('Z:/GitHub/reCaptcha/apikey.key', 'r').readlines()
alline = open('Z:/GitHub/reCaptcha/apikey.key', 'r').read().count("\n") + 1
keyusage = int(random.randint(1,(alline)))
SWITCH,HOUNDIFY_CLIENT_ID,HOUNDIFY_CLIENT_KEY,MAIL = apikey[(keyusage - 1)].split(',')
creditcur = int(open(r"audio.ser", "r", encoding="utf-8-sig").read().count('[{0}]'.format(int(datetime.datetime.now().strftime("%Y%m%d"))-0) + '[{:0>5d}]'.format(keyusage)))
creditpre = int(open(r"audio.ser", "r", encoding="utf-8-sig").read().count('[{0}]'.format(int(datetime.datetime.now().strftime("%Y%m%d"))-1) + '[{:0>5d}]'.format(keyusage)))
if (creditcur < 24):
maxRusage += 1.0
pass
else:
maxRusage += 0.1
continue
creditpage = urllib.request.FancyURLopener({}).open(MAIL)
credithtml = creditpage.read()
open("page.html","w").write('{}'.format(credithtml).replace('\\n', '\n').replace('\\r', ''))
creditmpst = int(open(r"page.html", "r", encoding="utf-8-sig").read().count('{0}-{1:0>2d}-{2:0>2d}'.format(int(datetime.datetime.now().strftime("%Y"))-0,int(datetime.datetime.now().strftime("%m"))-0,int(datetime.datetime.now().strftime("%d"))-0)))
if (creditmpst < 1):
print("API KEY ACCEPTED : " + '[{0:0>2d}]'.format(creditcur) + '[{0:0>2d}]'.format(creditpre) + '[{0}]'.format(creditmpst))
pass
else:
print("API KEY GENERATE : " + '[{0:0>2d}]'.format(creditcur) + '[{0:0>2d}]'.format(creditpre) + '[{0}]'.format(creditmpst))
continue
print("HOUNDIFY ID : " + (HOUNDIFY_CLIENT_ID))
print("HOUNDIFY PW : " + (HOUNDIFY_CLIENT_KEY))
print("HOUNDIFY CLIENT : " + '[{0}]'.format(maxRusage) + '[{0}]'.format(sendusage) + '[{0}]'.format(usage) + '[{:0>5d}]'.format(keyusage))
print("HOUNDIFY CREDIT : " + '[{0:0>2d}]'.format(creditcur) + '[{0:0>2d}]'.format(creditpre) + '[{0}]'.format(creditmpst))
r.operation_timeout = 20
value = r.recognize_houndify(audio, client_id=HOUNDIFY_CLIENT_ID, client_key=HOUNDIFY_CLIENT_KEY)
if str is bytes:
result = u"{}".format(value).encode("utf-8")
else:
result = "{}".format(value)
with open("audio.log","w") as f:
f.write("Houndify : " + (result))
with open("audio.his","a") as f:
f.write("\nHoundify : " + (audiomp3) + ' ' + '[{0}]'.format(datetime.datetime.now().strftime("%Y%m%d")) + '[{:0>5d}]'.format(keyusage) + ' ' + (result))
sendusage = 'done'
print("HOUNDIFY OUTPUT : " + (value) + ' ' + '[{:0>5d}]'.format(keyusage))
return value
except sr.UnknownValueError:
value = ('Houndify Unknown Value Error')
print("HOUNDIFY UNKNOWN VALUE ERROR : "+ '[{:0>5d}]'.format(keyusage))
return value
except sr.RequestError as e:
value = ('Houndify Request Error')
print("COULD NOT REQUEST FROM HOUNDIFY SERVICE; {0}".format(e) + '[{:0>5d}]'.format(keyusage))
continue
if (maxRusage > 5.0) or (maxRusage == 5.0):
value = ('Houndify You have reached your daily credit limit')
print("Houndify You have reached your daily credit limit")
return value
else:
pass
else:
print("REJECTED")
return value
if __name__ == "__main__":
'''
os.system("start \"\" http://127.0.0.1:5000/captcha?url=Welcome")
'''
app.run(host="127.0.0.2", port=5000, threaded=True)
app.run(processes=8)
Can you explain about why can't remove "sr." and replace to "speech_recognition." and remove "r." and replace with "speech_recognition.Recognizer()." ?
Hi @DarKWinGTM,
why can't remove "sr."
There's no sr.
to remove in your code, so in a sense we already removed it.
remove "r." and replace with "speech_recognition.Recognizer()."
This is a Python thing. Consider the following code:
r = speech_recognition.Recognizer()
r.operation_timeout = 5 # seconds until timeout
value = r.recognize_houndify(audio, client_id=HOUNDIFY_CLIENT_ID, client_key=HOUNDIFY_CLIENT_KEY)
On line 1, we're making a Recognizer
object. On line 2, we're changing that object we made on line 1. On line 3, we're using that object we made on line 1.
On line 3, that object has the changes we made on line 2, because r
always refers to that single object.
Now consider this code:
speech_recognition.Recognizer().operation_timeout = 5 # seconds until timeout
value = speech_recognition.Recognizer().recognize_houndify(audio, client_id=HOUNDIFY_CLIENT_ID, client_key=HOUNDIFY_CLIENT_KEY)
On line 1, we're making a Recognizer
object, and then changing a property of that object. On line 2, we're making another, different Recognizer
object, and then using that object that we just made.
On line 2, we do not see the changes we made on line 1, because speech_recognition.Recognizer()
will create a new, different object - the changes were made to the line 1 object, not to the line 2 object that we're actually using. This is the difference between the two code snippets.
Thanks , Best reguard