summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/requirements.txt1
-rw-r--r--client/stt.py17
-rw-r--r--client/test.py20
3 files changed, 22 insertions, 16 deletions
diff --git a/client/requirements.txt b/client/requirements.txt
index 6ef94a2..c0710b0 100644
--- a/client/requirements.txt
+++ b/client/requirements.txt
@@ -1,5 +1,4 @@
APScheduler==2.1.2
-CherryPy==3.2.2
PyYAML==3.10
Pykka==1.2.0
argparse==1.2.1
diff --git a/client/stt.py b/client/stt.py
index b1e8648..e14ab26 100644
--- a/client/stt.py
+++ b/client/stt.py
@@ -2,7 +2,7 @@
# -*- coding: utf-8-*-
import traceback
import json
-import urllib2
+import requests
"""
The default Speech-to-Text implementation which relies on PocketSphinx.
@@ -103,6 +103,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):
"""
@@ -120,16 +121,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 "==================="
diff --git a/client/test.py b/client/test.py
index a239b0d..a8f12be 100644
--- a/client/test.py
+++ b/client/test.py
@@ -1,6 +1,7 @@
#!/usr/bin/env python2
# -*- coding: utf-8-*-
import os
+import sys
if os.environ.get('JASPER_HOME') is None:
os.environ['JASPER_HOME'] = '/home/pi'
@@ -9,11 +10,17 @@ import unittest
import argparse
from mock import patch
from urllib2 import URLError, urlopen
-import yaml
import test_mic
import g2p
import brain
+DEFAULT_PROFILE = {
+ 'prefers_email': False,
+ 'location': '08544',
+ 'timezone': 'US/Eastern',
+ 'phone_number': '012344321'
+}
+
def activeInternet():
try:
@@ -67,7 +74,7 @@ class TestG2P(unittest.TestCase):
class TestModules(unittest.TestCase):
def setUp(self):
- self.profile = yaml.safe_load(open("profile.yml", "r"))
+ self.profile = DEFAULT_PROFILE
self.send = False
def runConversation(self, query, inputs, module):
@@ -164,7 +171,7 @@ class TestBrain(unittest.TestCase):
@staticmethod
def _emptyBrain():
mic = test_mic.Mic([])
- profile = yaml.safe_load(open("profile.yml", "r"))
+ profile = DEFAULT_PROFILE
return brain.Brain(mic, profile)
@patch.object(brain, 'logError')
@@ -199,7 +206,7 @@ if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Test suite for the Jasper client code.')
parser.add_argument('--light', action='store_true',
- help="runs a subset of the tests (only requires Python dependencies)")
+ help='runs a subset of the tests (only requires Python dependencies)')
args = parser.parse_args()
test_cases = [TestBrain, TestModules]
@@ -212,4 +219,7 @@ if __name__ == '__main__':
for test_case in test_cases:
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(test_case))
- unittest.TextTestRunner(verbosity=2).run(suite)
+ result = unittest.TextTestRunner(verbosity=2).run(suite)
+
+ if not result.wasSuccessful():
+ sys.exit("Tests failed")