diff options
| -rw-r--r-- | .travis.yml | 9 | ||||
| -rw-r--r-- | README.md | 2 | ||||
| -rwxr-xr-x | boot/boot.py | 39 | ||||
| -rw-r--r-- | client/requirements.txt | 1 | ||||
| -rw-r--r-- | client/stt.py | 17 | ||||
| -rw-r--r-- | client/test.py | 20 |
6 files changed, 65 insertions, 23 deletions
diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..95079e7 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,9 @@ +language: python + +env: + - ARCH=x86 + +script: + - "pip install -r client/requirements.txt" + - "cd client && python test.py --light" + - "cd ../boot && python test.py" @@ -1,6 +1,8 @@ jasper-client ============= +<img src="https://travis-ci.org/jasperproject/jasper-client.svg?branch=master" alt="Build Status" /> + Client code for the Jasper voice computing platform. Jasper is an open source platform for developing always-on, voice-controlled applications. Learn more at [jasperproject.github.io](http://jasperproject.github.io/), where we have assembly and installation instructions, as well as extensive documentation. For the relevant disk image, please visit [SourceForge](http://sourceforge.net/projects/jasperproject/). diff --git a/boot/boot.py b/boot/boot.py index 22a36a5..cb49552 100755 --- a/boot/boot.py +++ b/boot/boot.py @@ -13,21 +13,45 @@ sys.path.append(lib_path) import speaker as speak speaker = speak.newSpeaker() -def configure(): + +def testConnection(): try: urllib2.urlopen("http://www.google.com").getcode() - print "CONNECTED TO INTERNET" - print "COMPILING DICTIONARY" - vocabcompiler.compile("../client/sentences.txt", "../client/dictionary.dic", "../client/languagemodel.lm") + except urllib2.URLError: + print "COULD NOT CONNECT TO NETWORK" + speaker.say( + "Warning: I was unable to connect to a network. Parts of the system may not work correctly, depending on your setup.") + + +def fail(message): + traceback.print_exc() + speaker.say(message) + + +def configure(): + try: + print "COMPILING DICTIONARY" + vocabcompiler.compile( + "../client/sentences.txt", "../client/dictionary.dic", "../client/languagemodel.lm") print "STARTING CLIENT PROGRAM" os.system("$JASPER_HOME/jasper/client/start.sh &") + except OSError: + print "BOOT FAILURE: OSERROR" + fail( + "There was a problem starting Jasper. You may be missing the language model and associated files. Please read the documentation to configure your Raspberry Pi.") + + except IOError: + print "BOOT FAILURE: IOERROR" + fail( + "There was a problem starting Jasper. You may have set permissions incorrectly on some part of the filesystem. Please read the documentation to configure your Raspberry Pi.") + except: - print "COULD NOT CONNECT TO NETWORK" - traceback.print_exc() - speaker.say("Hello, I could not connect to a network. Please read the documentation to configure your Raspberry Pi.") + print "BOOT FAILURE" + fail( + "There was a problem starting Jasper. Please read the documentation to configure your Raspberry Pi.") if __name__ == "__main__": print "==========STARTING JASPER CLIENT==========" @@ -35,4 +59,5 @@ if __name__ == "__main__": print "COPYRIGHT 2013 SHUBHRO SAHA, CHARLIE MARSH" print "==========================================" speaker.say("Hello.... I am Jasper... Please wait one moment.") + testConnection() configure() 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") |
