diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2014-08-09 20:01:26 -0700 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2014-08-09 20:01:26 -0700 |
| commit | a510d85e6e594172e31c622312309e2c5cbd9f0b (patch) | |
| tree | 645f0328db5fe2a3f2edd21b73a80851021747d5 /client/mic.py | |
| parent | 10a57e25f29bd4cdf8caf50d1ebeff20ac506b9d (diff) | |
| parent | 1eb5e58379f463f322e62a37ece2c2bd6d61c67d (diff) | |
| download | jasper-client-a510d85e6e594172e31c622312309e2c5cbd9f0b.tar.gz jasper-client-a510d85e6e594172e31c622312309e2c5cbd9f0b.zip | |
Merge pull request #118 from astahlman/master
LGTM! Thanks for the fine work and revisions.
Diffstat (limited to 'client/mic.py')
| -rw-r--r-- | client/mic.py | 64 |
1 files changed, 9 insertions, 55 deletions
diff --git a/client/mic.py b/client/mic.py index f4b70df..b4ef668 100644 --- a/client/mic.py +++ b/client/mic.py @@ -10,66 +10,23 @@ import pyaudio import alteration -# quirky bug where first import doesn't work -try: - import pocketsphinx as ps -except: - import pocketsphinx as ps - - class Mic: speechRec = None speechRec_persona = None - def __init__(self, speaker, lmd, dictd, lmd_persona, dictd_persona, lmd_music=None, dictd_music=None): + def __init__(self, speaker, passive_stt_engine, active_stt_engine): """ Initiates the pocketsphinx instance. Arguments: speaker -- handles platform-independent audio output - lmd -- filename of the full language model - dictd -- filename of the full dictionary (.dic) - lmd_persona -- filename of the 'Persona' language model (containing, e.g., 'Jasper') - dictd_persona -- filename of the 'Persona' dictionary (.dic) + passive_stt_engine -- performs STT while Jasper is in passive listen mode + acive_stt_engine -- performs STT while Jasper is in active listen mode """ self.speaker = speaker - 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_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 TTS, 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 - """ - - 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() - - print "===================" - print "JASPER: " + result[0] - print "===================" - - return result[0] + self.passive_stt_engine = passive_stt_engine + self.active_stt_engine = active_stt_engine def getScore(self, data): rms = audioop.rms(data, 2) @@ -210,7 +167,7 @@ class Mic: write_frames.close() # check if PERSONA was said - transcribed = self.transcribe(AUDIO_FILE, PERSONA_ONLY=True) + transcribed = self.passive_stt_engine.transcribe(AUDIO_FILE, PERSONA_ONLY=True) if PERSONA in transcribed: return (THRESHOLD, PERSONA) @@ -223,7 +180,7 @@ class Mic: """ AUDIO_FILE = "active.wav" - RATE = 16000 + RATE = 16000 CHUNK = 1024 LISTEN_TIME = 12 @@ -232,7 +189,7 @@ class Mic: if not os.path.exists(AUDIO_FILE): return None - return self.transcribe(AUDIO_FILE) + return self.active_stt_engine.transcribe(AUDIO_FILE) # check if no threshold provided if THRESHOLD == None: @@ -284,10 +241,7 @@ class Mic: # DO SOME AMPLIFICATION # os.system("sox "+AUDIO_FILE+" temp.wav vol 20dB") - if MUSIC: - return self.transcribe(AUDIO_FILE, MUSIC=True) - - return self.transcribe(AUDIO_FILE) + return self.active_stt_engine.transcribe(AUDIO_FILE, MUSIC) def say(self, phrase, OPTIONS=" -vdefault+m3 -p 40 -s 160 --stdout > say.wav"): # alter phrase before speaking |
