Browse Source

Implemented -i flag to select UI and -c flag to start UI in 'continuous listen' mode

giggity
Jezra 11 years ago
parent
commit
bb744e1556
4 changed files with 42 additions and 15 deletions
  1. 23
    9
      Blather.py
  2. 5
    2
      GtkUI.py
  3. 5
    1
      QtUI.py
  4. 9
    3
      README

+ 23
- 9
Blather.py View File

@@ -8,7 +8,8 @@ import signal
8 8
 import gobject
9 9
 import os.path
10 10
 import subprocess
11
-from Recognizer import Recognizer
11
+from optparse import OptionParser
12
+
12 13
 
13 14
 #where are the files?
14 15
 conf_dir = os.path.expanduser("~/.config/blather")
@@ -22,26 +23,30 @@ if not os.path.exists(lang_dir):
22 23
 	os.makedirs(lang_dir)
23 24
 
24 25
 class Blather:
25
-	def __init__(self, args):
26
+	def __init__(self, opts):
27
+		#import the recognizer so Gst doesn't clobber our -h
28
+		from Recognizer import Recognizer
26 29
 		self.ui = None
30
+		ui_continuous_listen = False
27 31
 		self.continuous_listen = False
28 32
 		self.commands = {}
29 33
 		self.read_commands()
30 34
 		self.recognizer = Recognizer(lang_file, dic_file)
31 35
 		self.recognizer.connect('finished',self.recognizer_finished)
32
-		#is there an arg?
33
-		if len(args) > 1:
34
-			if args[1] == "-qt":
36
+		
37
+		if opts.interface != None:
38
+			if opts.interface == "q":
35 39
 				#import the ui from qt
36 40
 				from QtUI import UI
37
-			elif args[1] == "-gtk":
41
+			elif opts.interface == "g":
38 42
 				from GtkUI import UI
39 43
 			else:
40 44
 				print "no GUI defined"
41 45
 				sys.exit()
42
-			self.ui = UI(args)
46
+				
47
+			self.ui = UI(args,opts.continuous)
43 48
 			self.ui.connect("command", self.process_command)
44
-
49
+					
45 50
 	def read_commands(self):
46 51
 		#read the.commands file
47 52
 		file_lines = open(command_file)
@@ -105,8 +110,17 @@ class Blather:
105 110
 			self.quit()
106 111
 		
107 112
 if __name__ == "__main__":
113
+	parser = OptionParser()
114
+	parser.add_option("-i", "--interface",  type="string", dest="interface",
115
+		action='store',
116
+		help="Interface to use (if any). 'q' for Qt, 'g' for GTK")
117
+	parser.add_option("-c", "--continuous",
118
+		action="store_true", dest="continuous", default=False,
119
+		help="starts interface with 'continuous' listen enabled")
120
+
121
+	(options, args) = parser.parse_args()
108 122
 	#make our blather object
109
-	blather = Blather(sys.argv)
123
+	blather = Blather(options)
110 124
 	#init gobject threads
111 125
 	gobject.threads_init()
112 126
 	#we want a main loop

+ 5
- 2
GtkUI.py View File

@@ -12,8 +12,9 @@ class UI(gobject.GObject):
12 12
 		'command' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING,))
13 13
 	}
14 14
 	
15
-	def __init__(self,args):
15
+	def __init__(self,args, continuous):
16 16
 		gobject.GObject.__init__(self)
17
+		self.continuous = continuous
17 18
 		#make a window
18 19
 		self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
19 20
 		self.window.connect("delete_event", self.delete_event)
@@ -37,7 +38,7 @@ class UI(gobject.GObject):
37 38
 		#add a label to the UI to display the last command
38 39
 		self.label = gtk.Label()
39 40
 		layout.add(self.label)
40
-	
41
+
41 42
 	def ccheckbox_clicked(self, widget):
42 43
 		checked = self.ccheckbox.get_active()
43 44
 		self.lsbutton.set_sensitive(not checked)
@@ -63,6 +64,8 @@ class UI(gobject.GObject):
63 64
 			
64 65
 	def run(self):
65 66
 		self.window.show_all()
67
+		if self.continuous:
68
+			self.ccheckbox.set_active(True)
66 69
 	
67 70
 	def quit(self):
68 71
 		pass

+ 5
- 1
QtUI.py View File

@@ -13,7 +13,8 @@ class UI(gobject.GObject):
13 13
 		'command' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING,))
14 14
 	}
15 15
 	
16
-	def __init__(self,args):
16
+	def __init__(self,args,continuous):
17
+		self.continuous = continuous
17 18
 		gobject.GObject.__init__(self)
18 19
 		#start by making our app
19 20
 		self.app = QApplication(args)
@@ -69,6 +70,9 @@ class UI(gobject.GObject):
69 70
 			
70 71
 	def run(self):
71 72
 		self.window.show()
73
+		if self.continuous:
74
+			self.ccheckbox.setCheckState(Qt.Checked)
75
+			self.ccheckbox_clicked()
72 76
 		self.app.exec_()
73 77
 		self.emit("command", "quit")
74 78
 	

+ 9
- 3
README View File

@@ -15,9 +15,15 @@ Blather is a speech recognizer that will run commands when a user speaks preset
15 15
 4. download the resulting XXXX.lm file to the ~/.config/blather/language directory and rename to file to 'lm'
16 16
 5. download the resulting XXXX.dic file to the ~/.config/blather/language directory and rename to file to 'dic'
17 17
 6. run Blather.py
18
-    * for Qt GUI, run Blather.py -qt
19
-    * for Gtk GUI, run Blather.py -gtk
18
+    * for Qt GUI, run Blather.py -i q
19
+    * for Gtk GUI, run Blather.py -i g
20
+    * to start a UI in 'continuous' listen mode, use the -c flag  
21
+
20 22
 7. start talking
21 23
 
22 24
 ####Bonus
23
-once the sentences.corpus file has been created, run the language_updater.sh script to automate the process of creating and downloading language files.
25
+once the sentences.corpus file has been created, run the language_updater.sh script to automate the process of creating and downloading language files.
26
+
27
+**Example**  
28
+To run blather with the GTK UI and start in continuous listen mode:   
29
+./Blather.py -i g -c

Loading…
Cancel
Save