diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2014-09-08 17:10:56 -0400 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2014-09-08 17:10:56 -0400 |
| commit | 0b9d9a0c37d5540eb6a9b3e2f11fa4e87675bb7e (patch) | |
| tree | 91b84a4f64d2d3fc527781f1025a596e6ee3b93a /client | |
| parent | 9b028c62ec245bd4a59cf7038e176483ab3a20e6 (diff) | |
| parent | f5b79ac15e0b5141c46a20a3af2d1feecdf6fbe4 (diff) | |
| download | jasper-client-0b9d9a0c37d5540eb6a9b3e2f11fa4e87675bb7e.tar.gz jasper-client-0b9d9a0c37d5540eb6a9b3e2f11fa4e87675bb7e.zip | |
Merge pull request #156 from alexsiri7/google_stt_persistent
Persistent connection for Google STT
Diffstat (limited to 'client')
| -rw-r--r-- | client/stt.py | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/client/stt.py b/client/stt.py index 1bce875..b59b974 100644 --- a/client/stt.py +++ b/client/stt.py @@ -1,6 +1,6 @@ import traceback import json -import urllib2 +import requests """ The default Speech-to-Text implementation which relies on PocketSphinx. @@ -101,6 +101,7 @@ class GoogleSTT(object): api_key - the public api key which allows access to Google APIs """ self.api_key = api_key + self.http = requests.Session() def transcribe(self, audio_file_path, PERSONA_ONLY=False, MUSIC=False): """ @@ -118,16 +119,12 @@ class GoogleSTT(object): wav.close() try: - req = urllib2.Request( - url, - data=data, - headers={ - 'Content-type': 'audio/l16; rate=%s' % GoogleSTT.RATE}) - response_url = urllib2.urlopen(req) - response_read = response_url.read() - response_read = response_read.decode('utf-8') + headers={ 'Content-type': 'audio/l16; rate=%s' % GoogleSTT.RATE} + response = self.http.post(url, data=data, headers=headers) + response.encoding = 'utf-8' + response_read = response.text decoded = json.loads(response_read.split("\n")[1]) - print response_read + text = decoded['result'][0]['alternative'][0]['transcript'] if text: print "===================" |
