Last active
May 1, 2017 17:48
-
-
Save mabdrabo/8126512 to your computer and use it in GitHub Desktop.
bash script that installs Sphinxbase, Pocketsphinx, Gstreamer, and plugins needed for Gstreamer to work with Pocketsphinx
and example.py file containing a simple example code.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Copyright (c) 2008 Carnegie Mellon University. | |
# | |
# You may modify and redistribute this file under the same terms as | |
# the CMU Sphinx system. See | |
# http://cmusphinx.sourceforge.net/html/LICENSE for more information. | |
# Edited by: Mahmoud Abdrabo on Wed Dec 25 2013 | |
import pygtk | |
pygtk.require('2.0') | |
import gtk | |
import pygst | |
pygst.require('0.10') | |
import gst | |
class App(object): | |
"""GStreamer/PocketSphinx app""" | |
def __init__(self): | |
"""Initialize a App object""" | |
self.init_gst() | |
def init_gst(self): | |
"""Initialize the speech components""" | |
self.pipeline = gst.parse_launch('gconfaudiosrc ! audioconvert ! audioresample ' | |
+ '! vader name=vad auto-threshold=true ' | |
+ '! pocketsphinx name=asr ! fakesink') | |
asr = self.pipeline.get_by_name('asr') | |
asr.connect('result', self.asr_result) | |
asr.set_property('configured', True) | |
bus = self.pipeline.get_bus() | |
bus.add_signal_watch() | |
bus.connect('message::application', self.application_message) | |
self.pipeline.set_state(gst.STATE_PAUSED) | |
def asr_result(self, asr, text, uttid): | |
"""Forward result signals on the bus to the main thread.""" | |
struct = gst.Structure('result') | |
struct.set_value('hyp', text) | |
struct.set_value('uttid', uttid) | |
asr.post_message(gst.message_new_application(asr, struct)) | |
def application_message(self, bus, msg): | |
"""Receive application messages from the bus.""" | |
msgtype = msg.structure.get_name() | |
if msgtype == 'result': | |
self.final_result(msg.structure['hyp'], msg.structure['uttid']) | |
self.pipeline.set_state(gst.STATE_PAUSED) | |
def final_result(self, hyp, uttid): | |
"""Insert the final result.""" | |
self.final_result = hyp | |
print "#######FINAL_TEXT: ", hyp | |
def start_listen(self): | |
app.pipeline.set_state(gst.STATE_PLAYING) | |
app = App() | |
app.start_listen() | |
gtk.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#Author: Mahmoud Abdrabo | |
#Date: 2013 Wed Dec 25, 3:16:04 | |
# copy/paste the following(without the '#') in your ~/.bashrc or ~/.bash_profile file | |
# export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH | |
# export PS_BASE=/usr/local | |
# export GST_PLUGIN_PATH=/usr/local/lib/gstreamer-0.10" | |
############################################################# | |
echo "Did you add the lines to your .bashrc/.bash_profile? (y,n)" | |
read answer | |
echo $answer | |
if [ "$answer" = "y" ]; then | |
sudo apt-get install subversion | |
svn checkout 'http://svn.code.sf.net/p/cmusphinx/code/branches/pocketsphinx-0.6' | |
cd pocketsphinx-0.6/sphinxbase/ | |
sudo apt-get install autoconf | |
sudo apt-get install libtool | |
./autogen.sh | |
make | |
sudo make install | |
cd ../pocketsphinx/ | |
./autogen.sh | |
make | |
sudo make install | |
sudo apt-get install python-pocketsphinx | |
sudo apt-get install pocketsphinx-hmm-wsj1 | |
sudo apt-get install pocketsphinx-lm-wsj | |
sudo apt-get install python-gst0.10 gstreamer0.10-plugins-good gstreamer0.10-plugins-bad gstreamer0.10-plugins-ugly | |
sudo apt-get install gstreamer0.10-pocketsphinx | |
sudo apt-get install gstreamer-tools | |
fi | |
if [ "$answer" = "n" ]; then | |
echo "You'd better do! open the freakin file!! :D" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment