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,7 +34,7 @@ class Blather:
34 34
 		self.continuous_listen = False
35 35
 		self.commands = {}
36 36
 		self.read_commands()
37
-		self.recognizer = Recognizer(lang_file, dic_file)
37
+		self.recognizer = Recognizer(lang_file, dic_file, opts.microphone )
38 38
 		self.recognizer.connect('finished',self.recognizer_finished)
39 39
 
40 40
 		if opts.interface != None:
@@ -155,6 +155,9 @@ if __name__ == "__main__":
155 155
 	parser.add_option("-H", "--history", type="int",
156 156
 		action="store", dest="history",
157 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 162
 	(options, args) = parser.parse_args()
160 163
 	#make our blather object

+ 17
- 8
README View File

@@ -1,9 +1,9 @@
1 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 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 7
 3. pyside (only required for the Qt based UI)
8 8
 4. pygtk (only required for the Gtk based UI)
9 9
 
@@ -17,13 +17,22 @@ Blather is a speech recognizer that will run commands when a user speaks preset
17 17
 6. run Blather.py
18 18
     * for Qt GUI, run Blather.py -i q
19 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 22
 7. start talking
23 23
 
24 24
 ####Bonus
25 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,11 +16,16 @@ class Recognizer(gobject.GObject):
16 16
 	__gsignals__ = {
17 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 20
 		gobject.GObject.__init__(self)
21 21
 		self.commands = {}
22
+		if src:
23
+			audio_src = 'alsasrc device="hw:%d,0"' % (src)
24
+		else:
25
+			audio_src = 'autoaudiosrc'
26
+
22 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 29
 		self.pipeline=gst.parse_launch( cmd )
25 30
 		#get the Auto Speech Recognition piece
26 31
 		asr=self.pipeline.get_by_name('asr')
@@ -31,10 +36,10 @@ class Recognizer(gobject.GObject):
31 36
 		#get the Voice Activity DEtectoR
32 37
 		self.vad = self.pipeline.get_by_name('vad')
33 38
 		self.vad.set_property('auto-threshold',True)
34
-		
39
+
35 40
 	def listen(self):
36 41
 		self.pipeline.set_state(gst.STATE_PLAYING)
37
-		
42
+
38 43
 	def pause(self):
39 44
 		self.vad.set_property('silent', True)
40 45
 		self.pipeline.set_state(gst.STATE_PAUSED)
@@ -42,4 +47,4 @@ class Recognizer(gobject.GObject):
42 47
 	def result(self, asr, text, uttid):
43 48
 		#emit finished
44 49
 		self.emit("finished", text)
45
-		
50
+

Loading…
Cancel
Save