summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/brain.py3
-rw-r--r--client/conversation.py16
-rwxr-xr-xclient/diagnose.py7
-rw-r--r--client/g2p.py23
-rw-r--r--client/jasperpath.py19
-rw-r--r--client/mic.py4
-rw-r--r--client/notifier.py7
-rw-r--r--client/stt.py21
-rw-r--r--client/vocabcompiler.py22
9 files changed, 76 insertions, 46 deletions
diff --git a/client/brain.py b/client/brain.py
index 039b1db..a1fdea4 100644
--- a/client/brain.py
+++ b/client/brain.py
@@ -3,6 +3,7 @@ import logging
import os
import pkgutil
import importlib
+import jasperpath
def logError():
@@ -41,7 +42,7 @@ class Brain(object):
module, a priority of 0 is assumed.
"""
- module_locations = [os.path.join(os.path.dirname(__file__), 'modules')]
+ module_locations = [jasperpath.PLUGIN_PATH]
module_names = [name for loader, name, ispkg in pkgutil.iter_modules(module_locations)]
modules = []
for name in module_names:
diff --git a/client/conversation.py b/client/conversation.py
index fe3e058..be9b8e9 100644
--- a/client/conversation.py
+++ b/client/conversation.py
@@ -46,14 +46,12 @@ class Conversation(object):
for notif in notifications:
print notif
- try:
- threshold, transcribed = self.mic.passiveListen(self.persona)
- except:
+ threshold, transcribed = self.mic.passiveListen(self.persona)
+ if not transcribed or not threshold:
continue
- if threshold:
- input = self.mic.activeListen(threshold)
- if input:
- self.delegateInput(input)
- else:
- self.mic.say("Pardon?")
+ input = self.mic.activeListen(threshold)
+ if input:
+ self.delegateInput(input)
+ else:
+ self.mic.say("Pardon?")
diff --git a/client/diagnose.py b/client/diagnose.py
index 415eb6e..28cd9c8 100755
--- a/client/diagnose.py
+++ b/client/diagnose.py
@@ -4,7 +4,7 @@ import re
import socket
import os
from subprocess import check_output, call
-
+import jasperpath
class Diagnostics:
@@ -15,9 +15,6 @@ class Diagnostics:
To add new checks, add a boolean returning method with a name that starts
with `check_`
"""
- @classmethod
- def jasper_modules_path(cls):
- return os.path.abspath('../../')
@classmethod
def check_network_connection(cls):
@@ -35,7 +32,7 @@ class Diagnostics:
@classmethod
def check_phonetisaurus_dictionary_file(cls):
- return os.path.isfile(os.path.join(cls.jasper_modules_path(), "phonetisaurus/g014b2b.fst"))
+ return os.path.isfile(os.path.join(jasperpath.APP_PATH, "..", "phonetisaurus/g014b2b.fst"))
@classmethod
def check_phonetisaurus_program(cls):
diff --git a/client/g2p.py b/client/g2p.py
index 3225c73..276f681 100644
--- a/client/g2p.py
+++ b/client/g2p.py
@@ -3,9 +3,22 @@ import os
import tempfile
import subprocess
import re
+import yaml
PHONE_MATCH = re.compile(r'<s> (.*) </s>')
-PHONETISAURUS_PATH = os.environ['JASPER_HOME'] + "/phonetisaurus"
+
+FST_MODEL = None
+
+# Try to get fst_model from config
+profile_path = os.path.join(os.path.dirname(__file__), 'profile.yml')
+if os.path.exists(profile_path):
+ with open(profile_path, 'r') as f:
+ profile = yaml.safe_load(f)
+ if 'pocketsphinx' in profile and 'fst_model' in profile['pocketsphinx']:
+ FST_MODEL = profile['pocketsphinx']['fst_model']
+
+if not FST_MODEL:
+ FST_MODEL = os.environ['JASPER_HOME'] + "/phonetisaurus/g014b2b.fst"
def parseLine(line):
@@ -17,8 +30,8 @@ def parseOutput(output):
def translateWord(word):
- out = subprocess.check_output(['phonetisaurus-g2p', '--model=%s' %
- PHONETISAURUS_PATH + "/g014b2b.fst", '--input=%s' % word])
+ out = subprocess.check_output(
+ ['phonetisaurus-g2p', '--model=%s' % FST_MODEL, '--input=%s' % word])
return parseLine(out)
@@ -36,8 +49,8 @@ def translateWords(words):
def translateFile(input_filename, output_filename=None):
- out = subprocess.check_output(['phonetisaurus-g2p', '--model=%s' %
- PHONETISAURUS_PATH + "/g014b2b.fst", '--input=%s' % input_filename, '--words', '--isfile'])
+ out = subprocess.check_output(
+ ['phonetisaurus-g2p', '--model=%s' % FST_MODEL, '--input=%s' % input_filename, '--words', '--isfile'])
out = parseOutput(out)
if output_filename:
diff --git a/client/jasperpath.py b/client/jasperpath.py
new file mode 100644
index 0000000..53534ff
--- /dev/null
+++ b/client/jasperpath.py
@@ -0,0 +1,19 @@
+# -*- coding: utf-8-*-
+import os
+
+# Jasper main directory
+APP_PATH = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), os.pardir))
+
+DATA_PATH = os.path.join(APP_PATH, "static")
+LIB_PATH = os.path.join(APP_PATH, "client")
+PLUGIN_PATH = os.path.join(LIB_PATH, "modules")
+
+CONFIG_PATH = os.path.expanduser(os.getenv('JASPER_CONFIG', '~/.jasper'))
+
+
+def config(*fname):
+ return os.path.join(CONFIG_PATH, *fname)
+
+
+def data(*fname):
+ return os.path.join(DATA_PATH, *fname)
diff --git a/client/mic.py b/client/mic.py
index 096610d..3150d4e 100644
--- a/client/mic.py
+++ b/client/mic.py
@@ -138,7 +138,7 @@ class Mic:
# no use continuing if no flag raised
if not didDetect:
print "No disturbance detected"
- return
+ return (None, None)
# cutoff any recording before this disturbance was detected
frames = frames[-20:]
@@ -232,7 +232,7 @@ class Mic:
write_frames.writeframes(''.join(frames))
write_frames.close()
- return self.active_stt_engine.transcribe(AUDIO_FILE, MUSIC)
+ return self.active_stt_engine.transcribe(AUDIO_FILE, MUSIC=MUSIC)
def say(self, phrase, OPTIONS=" -vdefault+m3 -p 40 -s 160 --stdout > say.wav"):
# alter phrase before speaking
diff --git a/client/notifier.py b/client/notifier.py
index 5c2d855..6911ed5 100644
--- a/client/notifier.py
+++ b/client/notifier.py
@@ -20,9 +20,10 @@ class Notifier(object):
def __init__(self, profile):
self.q = Queue.Queue()
self.profile = profile
- self.notifiers = [
- self.NotificationClient(self.handleEmailNotifications, None),
- ]
+ self.notifiers = []
+
+ if 'gmail_address' in profile and 'gmail_password' in profile:
+ self.notifiers.append(self.NotificationClient(self.handleEmailNotifications, None))
sched = Scheduler()
sched.start()
diff --git a/client/stt.py b/client/stt.py
index e14ab26..bcfdfba 100644
--- a/client/stt.py
+++ b/client/stt.py
@@ -1,8 +1,10 @@
#!/usr/bin/env python2
# -*- coding: utf-8-*-
+import os
import traceback
import json
import requests
+import yaml
"""
The default Speech-to-Text implementation which relies on PocketSphinx.
@@ -31,13 +33,24 @@ class PocketSphinxSTT(object):
except:
import pocketsphinx as ps
- hmdir = "/usr/local/share/pocketsphinx/model/hmm/en_US/hub4wsj_sc_8k"
+ hmm_dir = None
+
+ # Try to get hmm_dir from config
+ profile_path = os.path.join(os.path.dirname(__file__), 'profile.yml')
+ if os.path.exists(profile_path):
+ with open(profile_path, 'r') as f:
+ profile = yaml.safe_load(f)
+ if 'pocketsphinx' in profile and 'hmm_dir' in profile['pocketsphinx']:
+ hmm_dir = profile['pocketsphinx']['hmm_dir']
+
+ if not hmm_dir:
+ hmm_dir = "/usr/local/share/pocketsphinx/model/hmm/en_US/hub4wsj_sc_8k"
if lmd_music and dictd_music:
- self.speechRec_music = ps.Decoder(hmm=hmdir, lm=lmd_music, dict=dictd_music)
+ self.speechRec_music = ps.Decoder(hmm=hmm_dir, lm=lmd_music, dict=dictd_music)
self.speechRec_persona = ps.Decoder(
- hmm=hmdir, lm=lmd_persona, dict=dictd_persona)
- self.speechRec = ps.Decoder(hmm=hmdir, lm=lmd, dict=dictd)
+ hmm=hmm_dir, lm=lmd_persona, dict=dictd_persona)
+ self.speechRec = ps.Decoder(hmm=hmm_dir, lm=lmd, dict=dictd)
def transcribe(self, audio_file_path, PERSONA_ONLY=False, MUSIC=False):
"""
diff --git a/client/vocabcompiler.py b/client/vocabcompiler.py
index 1b4d94c..aba85ce 100644
--- a/client/vocabcompiler.py
+++ b/client/vocabcompiler.py
@@ -4,14 +4,8 @@
"""
import os
-import sys
-import glob
-
-mod_path = os.path.abspath('modules/')
-
-sys.path.append(mod_path)
-
import g2p
+from brain import Brain
def text2lm(in_filename, out_filename):
@@ -35,21 +29,15 @@ def compile(sentences, dictionary, languagemodel):
Gets the words and creates the dictionary
"""
- m = [os.path.basename(f)[:-3]
- for f in glob.glob(os.path.dirname("../client/modules/") + "/*.py")]
+ modules = Brain.get_modules()
words = []
- for module_name in m:
- try:
- exec("import %s" % module_name)
- eval("words.extend(%s.WORDS)" % module_name)
- except:
- pass # module probably doesn't have the property
-
- words = list(set(words))
+ for module in modules:
+ words.extend(module.WORDS)
# for spotify module
words.extend(["MUSIC", "SPOTIFY"])
+ words = list(set(words))
# create the dictionary
pronounced = g2p.translateWords(words)