From bb744e1556db4fe11be9c0fb6a29ba5643ec6fff Mon Sep 17 00:00:00 2001 From: Jezra Date: Mon, 10 Jun 2013 20:10:30 -0700 Subject: Implemented -i flag to select UI and -c flag to start UI in 'continuous listen' mode giggity --- Blather.py | 32 +++++++++++++++++++++++--------- GtkUI.py | 7 +++++-- QtUI.py | 6 +++++- README | 12 +++++++++--- 4 files changed, 42 insertions(+), 15 deletions(-) diff --git a/Blather.py b/Blather.py index 6b431a7..c534e71 100755 --- a/Blather.py +++ b/Blather.py @@ -8,7 +8,8 @@ import signal import gobject import os.path import subprocess -from Recognizer import Recognizer +from optparse import OptionParser + #where are the files? conf_dir = os.path.expanduser("~/.config/blather") @@ -22,26 +23,30 @@ if not os.path.exists(lang_dir): os.makedirs(lang_dir) class Blather: - def __init__(self, args): + def __init__(self, opts): + #import the recognizer so Gst doesn't clobber our -h + from Recognizer import Recognizer self.ui = None + ui_continuous_listen = False self.continuous_listen = False self.commands = {} self.read_commands() self.recognizer = Recognizer(lang_file, dic_file) self.recognizer.connect('finished',self.recognizer_finished) - #is there an arg? - if len(args) > 1: - if args[1] == "-qt": + + if opts.interface != None: + if opts.interface == "q": #import the ui from qt from QtUI import UI - elif args[1] == "-gtk": + elif opts.interface == "g": from GtkUI import UI else: print "no GUI defined" sys.exit() - self.ui = UI(args) + + self.ui = UI(args,opts.continuous) self.ui.connect("command", self.process_command) - + def read_commands(self): #read the.commands file file_lines = open(command_file) @@ -105,8 +110,17 @@ class Blather: self.quit() if __name__ == "__main__": + parser = OptionParser() + parser.add_option("-i", "--interface", type="string", dest="interface", + action='store', + help="Interface to use (if any). 'q' for Qt, 'g' for GTK") + parser.add_option("-c", "--continuous", + action="store_true", dest="continuous", default=False, + help="starts interface with 'continuous' listen enabled") + + (options, args) = parser.parse_args() #make our blather object - blather = Blather(sys.argv) + blather = Blather(options) #init gobject threads gobject.threads_init() #we want a main loop diff --git a/GtkUI.py b/GtkUI.py index 9d68fcc..d9aae7d 100644 --- a/GtkUI.py +++ b/GtkUI.py @@ -12,8 +12,9 @@ class UI(gobject.GObject): 'command' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING,)) } - def __init__(self,args): + def __init__(self,args, continuous): gobject.GObject.__init__(self) + self.continuous = continuous #make a window self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.connect("delete_event", self.delete_event) @@ -37,7 +38,7 @@ class UI(gobject.GObject): #add a label to the UI to display the last command self.label = gtk.Label() layout.add(self.label) - + def ccheckbox_clicked(self, widget): checked = self.ccheckbox.get_active() self.lsbutton.set_sensitive(not checked) @@ -63,6 +64,8 @@ class UI(gobject.GObject): def run(self): self.window.show_all() + if self.continuous: + self.ccheckbox.set_active(True) def quit(self): pass diff --git a/QtUI.py b/QtUI.py index 37910a5..c4a5a54 100644 --- a/QtUI.py +++ b/QtUI.py @@ -13,7 +13,8 @@ class UI(gobject.GObject): 'command' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING,)) } - def __init__(self,args): + def __init__(self,args,continuous): + self.continuous = continuous gobject.GObject.__init__(self) #start by making our app self.app = QApplication(args) @@ -69,6 +70,9 @@ class UI(gobject.GObject): def run(self): self.window.show() + if self.continuous: + self.ccheckbox.setCheckState(Qt.Checked) + self.ccheckbox_clicked() self.app.exec_() self.emit("command", "quit") diff --git a/README b/README index 8e70d2b..d5414c1 100644 --- a/README +++ b/README @@ -15,9 +15,15 @@ Blather is a speech recognizer that will run commands when a user speaks preset 4. download the resulting XXXX.lm file to the ~/.config/blather/language directory and rename to file to 'lm' 5. download the resulting XXXX.dic file to the ~/.config/blather/language directory and rename to file to 'dic' 6. run Blather.py - * for Qt GUI, run Blather.py -qt - * for Gtk GUI, run Blather.py -gtk + * for Qt GUI, run Blather.py -i q + * for Gtk GUI, run Blather.py -i g + * to start a UI in 'continuous' listen mode, use the -c flag + 7. start talking ####Bonus -once the sentences.corpus file has been created, run the language_updater.sh script to automate the process of creating and downloading language files. \ No newline at end of file +once the sentences.corpus file has been created, run the language_updater.sh script to automate the process of creating and downloading language files. + +**Example** +To run blather with the GTK UI and start in continuous listen mode: +./Blather.py -i g -c \ No newline at end of file -- cgit 1.4.1