Browse Source

added -H Num to keep track of blather history

this shit is untested!
Jezra 11 years ago
parent
commit
2888974007
1 changed files with 24 additions and 0 deletions
  1. 24
    0
      Blather.py

+ 24
- 0
Blather.py View File

16
 lang_dir = os.path.join(conf_dir, "language")
16
 lang_dir = os.path.join(conf_dir, "language")
17
 command_file = os.path.join(conf_dir, "commands")
17
 command_file = os.path.join(conf_dir, "commands")
18
 strings_file = os.path.join(conf_dir, "sentences.corpus")
18
 strings_file = os.path.join(conf_dir, "sentences.corpus")
19
+history_file = os.path.join(conf_dir, "blather.history")
19
 lang_file = os.path.join(lang_dir,'lm')
20
 lang_file = os.path.join(lang_dir,'lm')
20
 dic_file = os.path.join(lang_dir,'dic')
21
 dic_file = os.path.join(lang_dir,'dic')
21
 #make the lang_dir if it doesn't exist
22
 #make the lang_dir if it doesn't exist
27
 		#import the recognizer so Gst doesn't clobber our -h
28
 		#import the recognizer so Gst doesn't clobber our -h
28
 		from Recognizer import Recognizer
29
 		from Recognizer import Recognizer
29
 		self.ui = None
30
 		self.ui = None
31
+		#keep track of the opts
32
+		self.opts = opts
30
 		ui_continuous_listen = False
33
 		ui_continuous_listen = False
31
 		self.continuous_listen = False
34
 		self.continuous_listen = False
32
 		self.commands = {}
35
 		self.commands = {}
46
 				
49
 				
47
 			self.ui = UI(args,opts.continuous)
50
 			self.ui = UI(args,opts.continuous)
48
 			self.ui.connect("command", self.process_command)
51
 			self.ui.connect("command", self.process_command)
52
+		
53
+		if self.opts.history:
54
+			self.history = []
55
+		
49
 					
56
 					
50
 	def read_commands(self):
57
 	def read_commands(self):
51
 		#read the.commands file
58
 		#read the.commands file
65
 		#close the strings file
72
 		#close the strings file
66
 		strings.close()
73
 		strings.close()
67
 	
74
 	
75
+	def log_history(self,text):
76
+		if self.opts.history:
77
+			self.history.append(text)
78
+			if len(self.history) > self.opts.history:
79
+				#pop off the first item
80
+				self.history.pop(0)
81
+			
82
+			#open and truncate the blather history file
83
+			hfile = open(history_file, "w")
84
+			for line in self.history:
85
+				hfile.write( line+"\n")
86
+			#close the  file
87
+			hfile.close()
68
 	
88
 	
69
 	def recognizer_finished(self, recognizer, text):
89
 	def recognizer_finished(self, recognizer, text):
70
 		t = text.lower()
90
 		t = text.lower()
73
 			cmd = self.commands[t]
93
 			cmd = self.commands[t]
74
 			print cmd
94
 			print cmd
75
 			subprocess.call(cmd, shell=True)
95
 			subprocess.call(cmd, shell=True)
96
+			self.log_history(text)
76
 		else:
97
 		else:
77
 			print "no matching command"
98
 			print "no matching command"
78
 		#if there is a UI and we are not continuous listen
99
 		#if there is a UI and we are not continuous listen
117
 	parser.add_option("-c", "--continuous",
138
 	parser.add_option("-c", "--continuous",
118
 		action="store_true", dest="continuous", default=False,
139
 		action="store_true", dest="continuous", default=False,
119
 		help="starts interface with 'continuous' listen enabled")
140
 		help="starts interface with 'continuous' listen enabled")
141
+	parser.add_option("-H", "--history", type="int",
142
+		action="store", dest="history", 	
143
+		help="number of commands to store in history file")
120
 
144
 
121
 	(options, args) = parser.parse_args()
145
 	(options, args) = parser.parse_args()
122
 	#make our blather object
146
 	#make our blather object

Loading…
Cancel
Save