summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2014-08-22 09:32:35 +0800
committerschneefux <schneefux+commit@schneefux.xyz>2014-08-22 09:32:35 +0800
commit0d4bb63b3727e44c973d167be0d82c4c062648f6 (patch)
tree2cbdddfc90fef1c345582b576dd5c45da84f46d7
parent71ac7e8d50a3bc9ee814f334b938cda336377d4f (diff)
downloadjasper-client-0d4bb63b3727e44c973d167be0d82c4c062648f6.tar.gz
jasper-client-0d4bb63b3727e44c973d167be0d82c4c062648f6.zip
Minor style fixes: removed unused imports, commented-out code, etc.
-rwxr-xr-xboot/boot.py1
-rw-r--r--boot/test.py4
-rwxr-xr-xclient/conversation.py7
-rw-r--r--client/main.py3
-rw-r--r--client/mic.py13
-rw-r--r--client/populate.py19
-rw-r--r--client/stt.py64
7 files changed, 55 insertions, 56 deletions
diff --git a/boot/boot.py b/boot/boot.py
index 12b60eb..a8141cb 100755
--- a/boot/boot.py
+++ b/boot/boot.py
@@ -1,7 +1,6 @@
#!/usr/bin/env python
import os
-import json
import urllib2
import sys
diff --git a/boot/test.py b/boot/test.py
index af5f982..3d93936 100644
--- a/boot/test.py
+++ b/boot/test.py
@@ -16,10 +16,12 @@ sys.path.append(mod_path)
import g2p
+
class UnorderedList(list):
+
def __eq__(self, other):
return sorted(self) == sorted(other)
-
+
class TestVocabCompiler(unittest.TestCase):
diff --git a/client/conversation.py b/client/conversation.py
index bad5073..a5937da 100755
--- a/client/conversation.py
+++ b/client/conversation.py
@@ -3,6 +3,7 @@ from musicmode import *
from brain import Brain
from mpd import MPDClient
+
class Conversation(object):
def __init__(self, persona, mic, profile):
@@ -16,7 +17,7 @@ class Conversation(object):
"""A wrapper for querying brain."""
# check if input is meant to start the music module
- if any(x in text.upper() for x in ["SPOTIFY","MUSIC"]):
+ if any(x in text.upper() for x in ["SPOTIFY", "MUSIC"]):
# check if mpd client is running
try:
client = MPDClient()
@@ -24,7 +25,8 @@ class Conversation(object):
client.idletimeout = None
client.connect("localhost", 6600)
except:
- self.mic.say("I'm sorry. It seems that Spotify is not enabled. Please read the documentation to learn how to configure Spotify.")
+ self.mic.say(
+ "I'm sorry. It seems that Spotify is not enabled. Please read the documentation to learn how to configure Spotify.")
return
self.mic.say("Please give me a moment, I'm loading your Spotify playlists.")
@@ -32,7 +34,6 @@ class Conversation(object):
music_mode.handleForever()
return
-
self.brain.query(text)
def handleForever(self):
diff --git a/client/main.py b/client/main.py
index 3fc728f..fb0eaf0 100644
--- a/client/main.py
+++ b/client/main.py
@@ -33,7 +33,8 @@ if __name__ == "__main__":
print "stt_engine not specified in profile, defaulting to PocketSphinx"
stt_engine_type = "sphinx"
- mic = Mic(speaker.newSpeaker(), stt.PocketSphinxSTT(), stt.newSTTEngine(stt_engine_type, api_key=api_key))
+ mic = Mic(speaker.newSpeaker(), stt.PocketSphinxSTT(),
+ stt.newSTTEngine(stt_engine_type, api_key=api_key))
addendum = ""
if 'first_name' in profile:
diff --git a/client/mic.py b/client/mic.py
index b4ef668..abd16a3 100644
--- a/client/mic.py
+++ b/client/mic.py
@@ -3,7 +3,6 @@
"""
import os
-import json
from wave import open as open_audio
import audioop
import pyaudio
@@ -35,19 +34,14 @@ class Mic:
def fetchThreshold(self):
- # TODO: Consolidate all of these variables from the next three
- # functions
+ # TODO: Consolidate all of these variables from the next three functions
THRESHOLD_MULTIPLIER = 1.8
- AUDIO_FILE = "passive.wav"
RATE = 16000
CHUNK = 1024
# number of seconds to allow to establish threshold
THRESHOLD_TIME = 1
- # number of seconds to listen before forcing restart
- LISTEN_TIME = 10
-
# prepare recording stream
audio = pyaudio.PyAudio()
stream = audio.open(format=pyaudio.paInt16,
@@ -180,7 +174,7 @@ class Mic:
"""
AUDIO_FILE = "active.wav"
- RATE = 16000
+ RATE = 16000
CHUNK = 1024
LISTEN_TIME = 12
@@ -238,9 +232,6 @@ class Mic:
write_frames.writeframes(''.join(frames))
write_frames.close()
- # DO SOME AMPLIFICATION
- # os.system("sox "+AUDIO_FILE+" temp.wav vol 20dB")
-
return self.active_stt_engine.transcribe(AUDIO_FILE, MUSIC)
def say(self, phrase, OPTIONS=" -vdefault+m3 -p 40 -s 160 --stdout > say.wav"):
diff --git a/client/populate.py b/client/populate.py
index dd5ca48..054366e 100644
--- a/client/populate.py
+++ b/client/populate.py
@@ -4,6 +4,7 @@ import yaml
from pytz import timezone
import feedparser
+
def run():
profile = {}
@@ -49,7 +50,7 @@ def run():
def verifyLocation(place):
feed = feedparser.parse('http://rss.wunderground.com/auto/rss_full/' + place)
numEntries = len(feed['entries'])
- if numEntries==0:
+ if numEntries == 0:
return False
else:
print("Location saved as " + feed['feed']['description'][33:])
@@ -58,7 +59,7 @@ def run():
print(
"\nLocation should be a 5-digit US zipcode (e.g., 08544). If you are outside the US, insert the name of your nearest big town/city. For weather requests.")
location = raw_input("Location: ")
- while location and (verifyLocation(location)==False):
+ while location and (verifyLocation(location) == False):
print("Weather not found. Please try another location.")
location = raw_input("Location: ")
if location:
@@ -83,25 +84,23 @@ def run():
response = raw_input("Please choose email (E) or text message (T): ")
profile['prefers_email'] = (response == 'E')
- stt_engines = {
- "sphinx" : None,
- "google" : "GOOGLE_SPEECH"
+ stt_engines = {
+ "sphinx": None,
+ "google": "GOOGLE_SPEECH"
}
response = raw_input(
- "\nIf you would like to choose a specific STT engine, please specify which." +
- "\nAvailable implementations: %s. (Press Enter to default to PocketSphinx): " % stt_engines.keys())
+ "\nIf you would like to choose a specific STT engine, please specify which." +
+ "\nAvailable implementations: %s. (Press Enter to default to PocketSphinx): " % stt_engines.keys())
if (response in stt_engines):
profile["stt_engine"] = response
api_key_name = stt_engines[response]
if api_key_name:
key = raw_input("\nPlease enter your API key: ")
- profile["keys"] = { api_key_name : key }
+ profile["keys"] = {api_key_name: key}
else:
print("Unrecognized STT engine. Available implementations: %s" % stt_engines.keys())
profile["stt_engine"] = "sphinx"
-
-
# write to profile
print("Writing to profile...")
diff --git a/client/stt.py b/client/stt.py
index d261464..20150b4 100644
--- a/client/stt.py
+++ b/client/stt.py
@@ -1,4 +1,3 @@
-import os
import traceback
import json
import urllib2
@@ -6,11 +5,13 @@ import urllib2
"""
The default Speech-To-Text implementation which relies on PocketSphinx.
"""
+
+
class PocketSphinxSTT(object):
- def __init__(self, lmd = "languagemodel.lm", dictd = "dictionary.dic",
- lmd_persona = "languagemodel_persona.lm", dictd_persona = "dictionary_persona.dic",
- lmd_music=None, dictd_music=None, **kwargs):
+ def __init__(self, lmd="languagemodel.lm", dictd="dictionary.dic",
+ lmd_persona="languagemodel_persona.lm", dictd_persona="dictionary_persona.dic",
+ lmd_music=None, dictd_music=None, **kwargs):
"""
Initiates the pocketsphinx instance.
@@ -31,39 +32,39 @@ class PocketSphinxSTT(object):
hmdir = "/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=hmdir, 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)
def transcribe(self, audio_file_path, PERSONA_ONLY=False, MUSIC=False):
- """
- Performs STT, transcribing an audio file and returning the result.
+ """
+ Performs STT, transcribing an audio file and returning the result.
- Arguments:
- audio_file_path -- the path to the audio file to-be transcribed
- PERSONA_ONLY -- if True, uses the 'Persona' language model and dictionary
- MUSIC -- if True, uses the 'Music' language model and dictionary
- """
+ Arguments:
+ audio_file_path -- the path to the audio file to-be transcribed
+ PERSONA_ONLY -- if True, uses the 'Persona' language model and dictionary
+ MUSIC -- if True, uses the 'Music' language model and dictionary
+ """
- wavFile = file(audio_file_path, 'rb')
- wavFile.seek(44)
+ wavFile = file(audio_file_path, 'rb')
+ wavFile.seek(44)
- if MUSIC:
- self.speechRec_music.decode_raw(wavFile)
- result = self.speechRec_music.get_hyp()
- elif PERSONA_ONLY:
- self.speechRec_persona.decode_raw(wavFile)
- result = self.speechRec_persona.get_hyp()
- else:
- self.speechRec.decode_raw(wavFile)
- result = self.speechRec.get_hyp()
+ if MUSIC:
+ self.speechRec_music.decode_raw(wavFile)
+ result = self.speechRec_music.get_hyp()
+ elif PERSONA_ONLY:
+ self.speechRec_persona.decode_raw(wavFile)
+ result = self.speechRec_persona.get_hyp()
+ else:
+ self.speechRec.decode_raw(wavFile)
+ result = self.speechRec.get_hyp()
- print "==================="
- print "JASPER: " + result[0]
- print "==================="
+ print "==================="
+ print "JASPER: " + result[0]
+ print "==================="
- return result[0]
+ return result[0]
"""
Speech-To-Text implementation which relies on the Google Speech API.
@@ -88,6 +89,8 @@ Excerpt from sample profile.yml:
GOOGLE_SPEECH: $YOUR_KEY_HERE
"""
+
+
class GoogleSTT(object):
RATE = 16000
@@ -101,13 +104,14 @@ class GoogleSTT(object):
def transcribe(self, audio_file_path, PERSONA_ONLY=False, MUSIC=False):
"""
- Performs STT via the Google Speech API, transcribing an audio file
+ Performs STT via the Google Speech API, transcribing an audio file
and returning an English string.
Arguments:
audio_file_path -- the path to the .wav file to be transcribed
"""
- url = "https://www.google.com/speech-api/v2/recognize?output=json&client=chromium&key=%s&lang=%s&maxresults=6&pfilter=2" % (self.api_key, "en-us")
+ url = "https://www.google.com/speech-api/v2/recognize?output=json&client=chromium&key=%s&lang=%s&maxresults=6&pfilter=2" % (
+ self.api_key, "en-us")
wav = open(audio_file_path, 'rb')
data = wav.read()
@@ -143,6 +147,8 @@ Arguments:
engine_type - one of "sphinx" or "google"
kwargs - keyword arguments passed to the constructor of the STT engine
"""
+
+
def newSTTEngine(engine_type, **kwargs):
t = engine_type.lower()
if t == "sphinx":