I am using Nuance for speech recognition and I'm doing it with chunk request like this:
import Audio
import logging
import json
import requests
nuance_creds = 'credentials.json'
def listen():
source = Audio.Microphone(sample_rate=16000, chunk_size=1024)
source.open_stream()
while True:
try:
yield source.read()
except KeyboardInterrupt:
break
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG)
with open(nuance_creds, 'r') as raw_credentials: # reads the credentials for nuance api
credentials = json.loads(raw_credentials.read())
appId = credentials['appId']
appKey = credentials['appKey']
asrUrl = credentials['asrUrl']
asrEndpoint = credentials['asrEndpoint']
requestor_Id = 'fc2jvf7p'
base_url = '%s%s?appId=%s&appKey=%s&id=%s'
base_url = base_url % (asrUrl, asrEndpoint, appId, appKey, requestor_Id)
headers = {
'Content-Type': 'audio/x-wav;bit=16;codec=pcm;rate=16000',
'Accept-Language': 'en_US',
'Transfer-Encoding': 'chunked',
'Accept': 'text/plain',
'Accept-Topic': 'Dictation'
}
req = listen()
response = requests.post(url=base_url, data=req, headers=headers, timeout=10,
stream=True)
print 'You said: {}'.format(response.text)
In Audio class I am using alsaaudio to read buffer from the microphone, so read function returns raw audio. this script runs fine on regular desktop computer running ubuntu the problem starts when using raspberry pi(jessie lite), at the end of the post I am getting some warning like this
INFO:Starting new HTTPS connection (1): dictation.nuancemobility.net
WARNING:Connection pool is full, discarding connection: dictation.nuancemobility.net
You said: Hello
I tried using requests session to increase the number of pool connections but it seems it doing just nothing, even if I give 100 connections its not solving the problem, but on desktop computer it seems that even one connection is enough.
The script above is just for debugging, so in my project I'm already using it. but still this warning doesn't suppose to happen, so I really want to get rid of it.
with extended request:
session = requests.Session()
adapter = requests.adapters.HTTPAdapter(
pool_connections=100, pool_maxsize=100)
session.mount('https://', adapter)
session.post(url=base_url, data=req, headers=headers, timeout=10,
stream=True)