From fb324756d97219d62fb04e95f24287ce31366025 Mon Sep 17 00:00:00 2001 From: schneefux Date: Wed, 10 Sep 2014 17:48:25 +0200 Subject: Merged boot/boot.py into client/main.py --- boot/boot.py | 88 ++++------------------------------------------------------ client/main.py | 67 ++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 67 insertions(+), 88 deletions(-) diff --git a/boot/boot.py b/boot/boot.py index e807beb..c7afcfd 100755 --- a/boot/boot.py +++ b/boot/boot.py @@ -1,86 +1,8 @@ #!/usr/bin/env python2 # -*- coding: utf-8-*- - +# This file exists for backwards compatibility with older versions of jasper. +# It might be removed in future versions. import os -import sys - -# Set $JASPER_HOME -jasper_home = os.getenv("JASPER_HOME") -if not jasper_home or not os.path.exists(jasper_home): - if os.path.exists("/home/pi"): - jasper_home = "/home/pi" - os.environ["JASPER_HOME"] = jasper_home - else: - print("Error: $JASPER_HOME is not set.") - sys.exit(0) - -# Change CWD to $JASPER_HOME/jasper/boot -os.chdir(os.path.join(os.getenv("JASPER_HOME"), "jasper", "boot")) - -# Set $LD_LIBRARY_PATH -os.environ["LD_LIBRARY_PATH"] = "/usr/local/lib" - -# Set $PATH -path = os.getenv("PATH") -if path: - path = os.pathsep.join([path, "/usr/local/lib/"]) -else: - path = "/usr/local/lib/" -os.environ["PATH"] = path - -import traceback - -lib_path = os.path.abspath('../client') -sys.path.append(lib_path) - -from diagnose import Diagnostics -import vocabcompiler -import speaker as speak -speaker = speak.newSpeaker() - - -def testConnection(): - if Diagnostics.check_network_connection(): - print "CONNECTED TO INTERNET" - else: - 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 "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==========" - print "==========================================" - print "COPYRIGHT 2013 SHUBHRO SAHA, CHARLIE MARSH" - print "==========================================" - speaker.say("Hello.... I am Jasper... Please wait one moment.") - testConnection() - configure() +import runpy +script_path = os.path.join(os.path.dirname(__file__), os.pardir, "client", "main.py") +runpy.run_path(script_path, run_name="__main__") diff --git a/client/main.py b/client/main.py index 7167c95..b62271c 100755 --- a/client/main.py +++ b/client/main.py @@ -3,7 +3,6 @@ import os import sys -import shutil # Change CWD to $JASPER_HOME/jasper/client jasper_home = os.getenv("JASPER_HOME") @@ -13,17 +12,71 @@ if not jasper_home or not os.path.exists(jasper_home): os.chdir(os.path.join(jasper_home, "jasper", "client")) +# Set $LD_LIBRARY_PATH +os.environ["LD_LIBRARY_PATH"] = "/usr/local/lib" + +# Set $PATH +path = os.getenv("PATH") +if path: + path = os.pathsep.join([path, "/usr/local/lib/"]) +else: + path = "/usr/local/lib/" +os.environ["PATH"] = path + +import urllib2 +import traceback + +import vocabcompiler +import speaker as speak +speaker = speak.newSpeaker() + +def testConnection(): + try: + urllib2.urlopen("http://www.google.com").getcode() + print "CONNECTED TO INTERNET" + + 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) + #sys.exit(1) + +def configure(): + try: + print "COMPILING DICTIONARY" + vocabcompiler.compile( + "sentences.txt", "dictionary.dic", "languagemodel.lm") + print "STARTING CLIENT PROGRAM" + + 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 "BOOT FAILURE" + fail( + "There was a problem starting Jasper. Please read the documentation to configure your Raspberry Pi.") + +import shutil + old_client = os.path.abspath(os.path.join(os.pardir, "old_client")) if os.path.exists(old_client): shutil.rmtree(old_client) import yaml -import sys -import speaker import stt from conversation import Conversation - def isLocal(): return len(sys.argv) > 1 and sys.argv[1] == "--local" @@ -39,6 +92,10 @@ if __name__ == "__main__": print " Copyright 2013 Shubhro Saha & Charlie Marsh " print "===========================================================" + speaker.say("Hello.... I am Jasper... Please wait one moment.") + testConnection() + configure() + profile = yaml.safe_load(open("profile.yml", "r")) try: @@ -52,7 +109,7 @@ if __name__ == "__main__": print "stt_engine not specified in profile, defaulting to PocketSphinx" stt_engine_type = "sphinx" - mic = Mic(speaker.newSpeaker(), stt.PocketSphinxSTT(), + mic = Mic(speaker, stt.PocketSphinxSTT(), stt.newSTTEngine(stt_engine_type, api_key=api_key)) addendum = "" -- cgit v1.3.1