From a9f275825fa784ebc85cdcfb3aad5a7e02e7f01b Mon Sep 17 00:00:00 2001 From: schneefux Date: Fri, 19 Sep 2014 11:57:41 +0200 Subject: Use jasperpath in client/mic.py --- client/mic.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'client') diff --git a/client/mic.py b/client/mic.py index 3150d4e..6c428c0 100644 --- a/client/mic.py +++ b/client/mic.py @@ -8,7 +8,7 @@ from wave import open as open_audio import audioop import pyaudio import alteration - +import jasperpath class Mic: @@ -190,7 +190,7 @@ class Mic: if THRESHOLD == None: THRESHOLD = self.fetchThreshold() - self.speaker.play("../static/audio/beep_hi.wav") + self.speaker.play(jasperpath.data('audio', 'beep_hi.wav')) # prepare recording stream audio = pyaudio.PyAudio() @@ -219,7 +219,7 @@ class Mic: if average < THRESHOLD * 0.8: break - self.speaker.play("../static/audio/beep_lo.wav") + self.speaker.play(jasperpath.data('audio', 'beep_lo.wav')) # save the audio data stream.stop_stream() -- cgit v1.3.1 From c1ffb7015cf7385f5e374d0958d7d57bd3fdd31d Mon Sep 17 00:00:00 2001 From: schneefux Date: Fri, 19 Sep 2014 12:02:10 +0200 Subject: Use jasperpath in client/test.py --- client/test.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'client') diff --git a/client/test.py b/client/test.py index 8925e66..a731951 100644 --- a/client/test.py +++ b/client/test.py @@ -14,6 +14,7 @@ import test_mic import vocabcompiler import g2p import brain +import jasperpath from diagnose import Diagnostics DEFAULT_PROFILE = { @@ -59,8 +60,8 @@ class TestVocabCompiler(unittest.TestCase): class TestMic(unittest.TestCase): def setUp(self): - self.jasper_clip = "../static/audio/jasper.wav" - self.time_clip = "../static/audio/time.wav" + self.jasper_clip = jasperpath.data('audio', 'jasper.wav') + self.time_clip = jasperpath.data('audio', 'time.wav') from stt import PocketSphinxSTT self.stt = PocketSphinxSTT() @@ -134,7 +135,7 @@ class TestModules(unittest.TestCase): inputs = ["Who's there?", "Random response"] outputs = self.runConversation(query, inputs, Joke) self.assertEqual(len(outputs), 3) - allJokes = open("../static/text/JOKES.txt", "r").read() + allJokes = open(jasperpath.data('text','JOKES.txt'), 'r').read() self.assertTrue(outputs[2] in allJokes) def testTime(self): -- cgit v1.3.1 From 259c5798024d3a4136d55e6ffd2035b46df98fcb Mon Sep 17 00:00:00 2001 From: schneefux Date: Fri, 19 Sep 2014 12:04:04 +0200 Subject: Use jasperpath in client/modules/Joke.py --- client/modules/Joke.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'client') diff --git a/client/modules/Joke.py b/client/modules/Joke.py index 802047c..c560f4e 100644 --- a/client/modules/Joke.py +++ b/client/modules/Joke.py @@ -1,11 +1,12 @@ # -*- coding: utf-8-*- import random import re +import jasperpath WORDS = ["JOKE", "KNOCK KNOCK"] -def getRandomJoke(filename="../static/text/JOKES.txt"): +def getRandomJoke(filename=jasperpath.data('text','JOKES.txt')): jokeFile = open(filename, "r") jokes = [] start = "" -- cgit v1.3.1 From 3934c771b944e30e278f53be4480c6e5d24643bc Mon Sep 17 00:00:00 2001 From: schneefux Date: Fri, 19 Sep 2014 12:30:29 +0200 Subject: Replace JASPER_HOME with jasperpath.APP_PATH + os.pardir --- client/g2p.py | 4 +++- client/test.py | 5 +---- jasper.py | 19 +++++++------------ 3 files changed, 11 insertions(+), 17 deletions(-) (limited to 'client') diff --git a/client/g2p.py b/client/g2p.py index 276f681..6e308ef 100644 --- a/client/g2p.py +++ b/client/g2p.py @@ -5,6 +5,8 @@ import subprocess import re import yaml +import jasperpath + PHONE_MATCH = re.compile(r' (.*) ') FST_MODEL = None @@ -18,7 +20,7 @@ if os.path.exists(profile_path): FST_MODEL = profile['pocketsphinx']['fst_model'] if not FST_MODEL: - FST_MODEL = os.environ['JASPER_HOME'] + "/phonetisaurus/g014b2b.fst" + FST_MODEL = os.path.join(jasperpath.APP_PATH, os.pardir, 'phonetisaurus', 'g014b2b.fst') def parseLine(line): diff --git a/client/test.py b/client/test.py index a731951..49f3109 100644 --- a/client/test.py +++ b/client/test.py @@ -2,14 +2,11 @@ # -*- coding: utf-8-*- import os import sys - -if os.environ.get('JASPER_HOME') is None: - os.environ['JASPER_HOME'] = '/home/pi' - import unittest import argparse from mock import patch from urllib2 import URLError, urlopen + import test_mic import vocabcompiler import g2p diff --git a/jasper.py b/jasper.py index 346617f..62713ee 100755 --- a/jasper.py +++ b/jasper.py @@ -10,12 +10,8 @@ logger = logging.getLogger(__name__) import yaml import argparse -# Set $JASPER_HOME -if not os.getenv('JASPER_HOME'): - os.environ["JASPER_HOME"] = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)) - from client.diagnose import Diagnostics -from client import vocabcompiler, stt +from client import vocabcompiler, stt, jasperpath from client import speaker as speak from client.conversation import Conversation @@ -33,16 +29,15 @@ if args.local: else: from client.mic import Mic -# Change CWD to $JASPER_HOME/jasper/client -client_path = os.path.join(os.getenv("JASPER_HOME"), "jasper", "client") -os.chdir(client_path) -# Add $JASPER_HOME/jasper/client to sys.path -sys.path.append(client_path) +# Change CWD to jasperpath.LIB_PATH +os.chdir(jasperpath.LIB_PATH) +# Add jasperpath.LIB_PATH to sys.path +sys.path.append(jasperpath.LIB_PATH) class Jasper(object): def __init__(self): # Read config - config_file = os.path.abspath(os.path.join(client_path, 'profile.yml')) + config_file = os.path.abspath(os.path.join(jasperpath.LIB_PATH, 'profile.yml')) logger.debug("Trying to read config file: '%s'", config_file) with open(config_file, "r") as f: self.config = yaml.safe_load(f) @@ -59,7 +54,7 @@ class Jasper(object): logger.warning("stt_engine not specified in profile, defaulting to '%s'", stt_engine_type) # Compile dictionary - sentences, dictionary, languagemodel = [os.path.abspath(os.path.join(client_path, filename)) for filename in ("sentences.txt", "dictionary.dic", "languagemodel.lm")] + sentences, dictionary, languagemodel = [os.path.abspath(os.path.join(jasperpath.LIB_PATH, filename)) for filename in ("sentences.txt", "dictionary.dic", "languagemodel.lm")] vocabcompiler.compile(sentences, dictionary, languagemodel) # Initialize Mic -- cgit v1.3.1 From eb8ebf8c834beec1198999cf21b9223482db4c43 Mon Sep 17 00:00:00 2001 From: schneefux Date: Fri, 19 Sep 2014 12:36:26 +0200 Subject: Use os.chdir inside client/test.py Otherwise, the transcribe check will fail, if you execute test.py from outside the client directory, e.g. via `python2 client/test.py` It's a mess that we need os.chdir at all, but hopefully we can remove this soon, if absolute paths are used everywhere. --- client/test.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'client') diff --git a/client/test.py b/client/test.py index 49f3109..0160b76 100644 --- a/client/test.py +++ b/client/test.py @@ -233,6 +233,9 @@ if __name__ == '__main__': help='runs a subset of the tests (only requires Python dependencies)') args = parser.parse_args() + # Change CWD to jasperpath.LIB_PATH + os.chdir(jasperpath.LIB_PATH) + test_cases = [TestBrain, TestModules, TestVocabCompiler] if not args.light: test_cases.append(TestG2P) -- cgit v1.3.1