It works quite well on a proxy free.network but whenever I try to run it on a proxy.network it gives this error.
Could not request results from Google STT; recognition connection failed: [Errno 11001] getaddrinfo failed
Please help.
I was having similar issues for the last few days and after a lot of research I found out that sadly Google Speech API currently does not support proxies.
https://github.com/GoogleCloudPlatform/java-docs-samples/issues/1061#issuecomment-373478268
After many days working this issue I realized that speech_recognition python package, for desktop aplications (no cloud) is based on urllib that doesn´t support to proxies.
So I had to chage some code lines inside the google package speech recoginition to use requests package (which supports proxies) instead of urllib, such way to make it works:
In your <Home_python>\Lib\site-packages\speech_recognition folder open the init.py file and create a new method named def recognize_google_proxy(): Then copy def recognize_google() codes into def recognize_google_proxy().
Now you have two distict objects that makes the same thing.
Next, In the recognize_google_proxy() object, Change lines like described here:
Insert to replace bellow code snipet:
import requests
http_proxy = "http://<your proxy url>:port"
https_proxy = "https://<your proxy url>:port"
proxyDict = {
"http" : http_proxy,
"https" : https_proxy
}
Insert to replace bellow code snipet:
response = requests.post(url, data=flac_data, headers={"Content-Type": "audio/x-flac; rate={}".format(audio_data.sample_rate)},proxies=proxyDict)
Save init.py
import speech_recognition
That's all.
Now you have available one object without proxy support and using urllib named recognize_google() and another object, with proxy support, using requests named recognize_google_proxy().
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.