Browse Source

Added '-m --microphone' flag to let the user pick a mic other than the system default

Jezra 10 years ago
parent
commit
00b0cdb291
3 changed files with 31 additions and 14 deletions
  1. 4
    1
      Blather.py
  2. 17
    8
      README
  3. 10
    5
      Recognizer.py

+ 4
- 1
Blather.py View File

34
 		self.continuous_listen = False
34
 		self.continuous_listen = False
35
 		self.commands = {}
35
 		self.commands = {}
36
 		self.read_commands()
36
 		self.read_commands()
37
-		self.recognizer = Recognizer(lang_file, dic_file)
37
+		self.recognizer = Recognizer(lang_file, dic_file, opts.microphone )
38
 		self.recognizer.connect('finished',self.recognizer_finished)
38
 		self.recognizer.connect('finished',self.recognizer_finished)
39
 
39
 
40
 		if opts.interface != None:
40
 		if opts.interface != None:
155
 	parser.add_option("-H", "--history", type="int",
155
 	parser.add_option("-H", "--history", type="int",
156
 		action="store", dest="history",
156
 		action="store", dest="history",
157
 		help="number of commands to store in history file")
157
 		help="number of commands to store in history file")
158
+	parser.add_option("-m", "--microphone", type="int",
159
+		action="store", dest="microphone", default=None,
160
+		help="Audio input card to use (if other than system default)")
158
 
161
 
159
 	(options, args) = parser.parse_args()
162
 	(options, args) = parser.parse_args()
160
 	#make our blather object
163
 	#make our blather object

+ 17
- 8
README View File

1
 #Blather
1
 #Blather
2
-Blather is a speech recognizer that will run commands when a user speaks preset sentences. 
2
+Blather is a speech recognizer that will run commands when a user speaks preset sentences.
3
 
3
 
4
 ##Requirements
4
 ##Requirements
5
-1. pocketsphinx	
6
-2. gstreamer (and what ever plugin has pocket sphinx support)  
5
+1. pocketsphinx
6
+2. gstreamer (and what ever plugin has pocket sphinx support)
7
 3. pyside (only required for the Qt based UI)
7
 3. pyside (only required for the Qt based UI)
8
 4. pygtk (only required for the Gtk based UI)
8
 4. pygtk (only required for the Gtk based UI)
9
 
9
 
17
 6. run Blather.py
17
 6. run Blather.py
18
     * for Qt GUI, run Blather.py -i q
18
     * for Qt GUI, run Blather.py -i q
19
     * for Gtk GUI, run Blather.py -i g
19
     * for Gtk GUI, run Blather.py -i g
20
-    * to start a UI in 'continuous' listen mode, use the -c flag  
21
-
20
+    * to start a UI in 'continuous' listen mode, use the -c flag
21
+    * to use a microphone other than the system default, use the -d flag
22
 7. start talking
22
 7. start talking
23
 
23
 
24
 ####Bonus
24
 ####Bonus
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.
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
 
26
 
27
-**Example**  
28
-To run blather with the GTK UI and start in continuous listen mode:   
29
-./Blather.py -i g -c
27
+####Examples
28
+To run blather with the GTK UI and start in continuous listen mode:
29
+./Blather.py -i g -c
30
+
31
+To run blather with no UI and using a USB microphone recognized and device 2:
32
+./Blather.py -d 2
33
+
34
+####Finding the Device Number of a USB microphone
35
+There are a few ways to find the device number of a USB microphone.
36
+
37
+* `cat /proc/asound/cards`
38
+* `arecord -l`

+ 10
- 5
Recognizer.py View File

16
 	__gsignals__ = {
16
 	__gsignals__ = {
17
 		'finished' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING,))
17
 		'finished' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING,))
18
 	}
18
 	}
19
-	def __init__(self, language_file, dictionary_file):
19
+	def __init__(self, language_file, dictionary_file, src = None):
20
 		gobject.GObject.__init__(self)
20
 		gobject.GObject.__init__(self)
21
 		self.commands = {}
21
 		self.commands = {}
22
+		if src:
23
+			audio_src = 'alsasrc device="hw:%d,0"' % (src)
24
+		else:
25
+			audio_src = 'autoaudiosrc'
26
+
22
 		#build the pipeline
27
 		#build the pipeline
23
-		cmd = 'autoaudiosrc ! audioconvert ! audioresample ! vader name=vad ! pocketsphinx name=asr ! appsink sync=false'
28
+		cmd = audio_src+' ! audioconvert ! audioresample ! vader name=vad ! pocketsphinx name=asr ! appsink sync=false'
24
 		self.pipeline=gst.parse_launch( cmd )
29
 		self.pipeline=gst.parse_launch( cmd )
25
 		#get the Auto Speech Recognition piece
30
 		#get the Auto Speech Recognition piece
26
 		asr=self.pipeline.get_by_name('asr')
31
 		asr=self.pipeline.get_by_name('asr')
31
 		#get the Voice Activity DEtectoR
36
 		#get the Voice Activity DEtectoR
32
 		self.vad = self.pipeline.get_by_name('vad')
37
 		self.vad = self.pipeline.get_by_name('vad')
33
 		self.vad.set_property('auto-threshold',True)
38
 		self.vad.set_property('auto-threshold',True)
34
-		
39
+
35
 	def listen(self):
40
 	def listen(self):
36
 		self.pipeline.set_state(gst.STATE_PLAYING)
41
 		self.pipeline.set_state(gst.STATE_PLAYING)
37
-		
42
+
38
 	def pause(self):
43
 	def pause(self):
39
 		self.vad.set_property('silent', True)
44
 		self.vad.set_property('silent', True)
40
 		self.pipeline.set_state(gst.STATE_PAUSED)
45
 		self.pipeline.set_state(gst.STATE_PAUSED)
42
 	def result(self, asr, text, uttid):
47
 	def result(self, asr, text, uttid):
43
 		#emit finished
48
 		#emit finished
44
 		self.emit("finished", text)
49
 		self.emit("finished", text)
45
-		
50
+

Loading…
Cancel
Save