diff options
-rwxr-xr-x | Blather.py | 54 | ||||
-rw-r--r-- | GtkUI.py | 22 | ||||
-rw-r--r-- | QtUI.py | 19 | ||||
-rw-r--r-- | README.md (renamed from README) | 15 | ||||
-rw-r--r-- | options.yaml.tmp | 6 |
5 files changed, 94 insertions, 22 deletions
diff --git a/Blather.py b/Blather.py index 6ec6b02..60ca6bb 100755 --- a/Blather.py +++ b/Blather.py @@ -9,7 +9,10 @@ import gobject import os.path import subprocess from optparse import OptionParser - +try: + import yaml +except: + print "YAML is not supported. ~/.config/blather/options.yaml will not function" #where are the files? conf_dir = os.path.expanduser("~/.config/blather") @@ -17,6 +20,7 @@ lang_dir = os.path.join(conf_dir, "language") command_file = os.path.join(conf_dir, "commands.conf") strings_file = os.path.join(conf_dir, "sentences.corpus") history_file = os.path.join(conf_dir, "blather.history") +opt_file = os.path.join(conf_dir, "options.yaml") lang_file = os.path.join(lang_dir,'lm') dic_file = os.path.join(lang_dir,'dic') #make the lang_dir if it doesn't exist @@ -28,8 +32,7 @@ class Blather: #import the recognizer so Gst doesn't clobber our -h from Recognizer import Recognizer self.ui = None - #keep track of the opts - self.opts = opts + self.options = {} ui_continuous_listen = False self.continuous_listen = False self.commands = {} @@ -37,27 +40,40 @@ class Blather: self.recognizer = Recognizer(lang_file, dic_file, opts.microphone ) self.recognizer.connect('finished',self.recognizer_finished) - if opts.interface != None: - if opts.interface == "q": - #import the ui from qt + #load the options file + self.load_options() + #merge the opts + for k,v in opts.__dict__.items(): + if not k in self.options: + self.options[k] = v + + print "Using Options: ", self.options + + if self.options['interface'] != None: + if self.options['interface'] == "q": from QtUI import UI - elif opts.interface == "g": + elif self.options['interface'] == "g": from GtkUI import UI + elif self.options['interface'] == "gt": + from GtkTrayUI import UI else: print "no GUI defined" sys.exit() - self.ui = UI(args,opts.continuous) + self.ui = UI(args, self.options['continuous']) self.ui.connect("command", self.process_command) #can we load the icon resource? icon = self.load_resource("icon.png") if icon: - self.ui.set_icon(icon) + self.ui.set_icon_active_asset(icon) + #can we load the icon_inactive resource? + icon_inactive = self.load_resource("icon_inactive.png") + if icon_inactive: + self.ui.set_icon_inactive_asset(icon_inactive) - if self.opts.history: + if self.options['history']: self.history = [] - def read_commands(self): #read the.commands file file_lines = open(command_file) @@ -76,10 +92,20 @@ class Blather: #close the strings file strings.close() + def load_options(self): + #is there an opt file? + try: + opt_fh = open(opt_file) + text = opt_fh.read() + self.options = yaml.load(text) + except: + pass + + def log_history(self,text): - if self.opts.history: + if self.options['history']: self.history.append(text) - if len(self.history) > self.opts.history: + if len(self.history) > self.options['history']: #pop off the first item self.history.pop(0) @@ -148,7 +174,7 @@ 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") + help="Interface to use (if any). 'q' for Qt, 'g' for GTK, 'gt' for GTK system tray icon") parser.add_option("-c", "--continuous", action="store_true", dest="continuous", default=False, help="starts interface with 'continuous' listen enabled") diff --git a/GtkUI.py b/GtkUI.py index 56a6252..71255fc 100644 --- a/GtkUI.py +++ b/GtkUI.py @@ -54,8 +54,10 @@ class UI(gobject.GObject): if checked: self.lsbutton_stopped() self.emit('command', "continuous_listen") + self.set_icon_active() else: self.emit('command', "continuous_stop") + self.set_icon_inactive() def lsbutton_stopped(self): self.lsbutton.set_label("Listen") @@ -67,13 +69,18 @@ class UI(gobject.GObject): self.lsbutton.set_label("Stop") #clear the label self.label.set_text("") + self.set_icon_active() else: self.lsbutton_stopped() self.emit("command", "stop") + self.set_icon_inactive() def run(self): + #set the default icon + self.set_icon_inactive() self.window.show_all() if self.continuous: + self.set_icon_active() self.ccheckbox.set_active(True) def accel_quit(self, accel_group, acceleratable, keyval, modifier): @@ -87,8 +94,19 @@ class UI(gobject.GObject): #if the continuous isn't pressed if not self.ccheckbox.get_active(): self.lsbutton_stopped() + self.set_icon_inactive() self.label.set_text(text) - def set_icon(self, icon): - gtk.window_set_default_icon_from_file(icon) + def set_icon_active_asset(self, i): + self.icon_active = i + + def set_icon_inactive_asset(self, i): + self.icon_inactive = i + + def set_icon_active(self): + gtk.window_set_default_icon_from_file(self.icon_active) + + def set_icon_inactive(self): + gtk.window_set_default_icon_from_file(self.icon_inactive) + diff --git a/QtUI.py b/QtUI.py index c772abf..4b17d9f 100644 --- a/QtUI.py +++ b/QtUI.py @@ -60,9 +60,11 @@ class UI(gobject.GObject): self.lsbutton.setEnabled(False) self.lsbutton_stopped() self.emit('command', "continuous_listen") + self.set_icon_active() else: self.lsbutton.setEnabled(True) self.emit('command', "continuous_stop") + self.set_icon_inactive() def lsbutton_stopped(self): self.lsbutton.setText("Listen") @@ -74,13 +76,17 @@ class UI(gobject.GObject): self.lsbutton.setText("Stop") #clear the label self.label.setText("") + self.set_icon_active() else: self.lsbutton_stopped() self.emit("command", "stop") + self.set_icon_inactive() def run(self): + self.set_icon_inactive() self.window.show() if self.continuous: + self.set_icon_active() self.ccheckbox.setCheckState(Qt.Checked) self.ccheckbox_clicked() self.app.exec_() @@ -95,3 +101,16 @@ class UI(gobject.GObject): def set_icon(self, icon): self.window.setWindowIcon(QIcon(icon)) + + def set_icon_active_asset(self, i): + self.icon_active = i + + def set_icon_inactive_asset(self, i): + self.icon_inactive = i + + def set_icon_active(self): + self.window.setWindowIcon(QIcon(self.icon_active)) + + def set_icon_inactive(self): + self.window.setWindowIcon(QIcon(self.icon_inactive)) + diff --git a/README b/README.md index 1ab0da0..6b3e365 100644 --- a/README +++ b/README.md @@ -7,6 +7,7 @@ Blather is a speech recognizer that will run commands when a user speaks preset 3. gstreamer-0.10 base plugins (required for alsa) 4. pyside (only required for the Qt based UI) 5. pygtk (only required for the Gtk based UI) +6. pyyaml (only required for reading the options file) ##Usage 0. move commands.tmp to ~/.config/blather/commands.conf and fill the file with sentences and command to run @@ -19,20 +20,22 @@ Blather is a speech recognizer that will run commands when a user speaks preset * 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 - * to use a microphone other than the system default, use the -d flag + * to use a microphone other than the system default, use the -m flag 7. start talking -####Bonus +**Note:** to start Blather without needing to enter command line options all the time, copy options.yaml.tmp to ~/.config/blather/options.yaml and edit accordingly. + +###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. -####Examples +###Examples To run blather with the GTK UI and start in continuous listen mode: -./Blather.py -i g -c +`./Blather.py -i g -c` To run blather with no UI and using a USB microphone recognized and device 2: -./Blather.py -d 2 +`./Blather.py -m 2` -####Finding the Device Number of a USB microphone +###Finding the Device Number of a USB microphone There are a few ways to find the device number of a USB microphone. * `cat /proc/asound/cards` diff --git a/options.yaml.tmp b/options.yaml.tmp new file mode 100644 index 0000000..e399b56 --- /dev/null +++ b/options.yaml.tmp @@ -0,0 +1,6 @@ +#This is a YAML file +#these options can be over-ridden by commandline arguments +continuous: false +history: null +microphone: null +interface: null |