summary refs log tree commit diff
diff options
context:
space:
mode:
-rwxr-xr-xBlather.py5
-rw-r--r--README25
-rwxr-xr-xRecognizer.py15
3 files changed, 31 insertions, 14 deletions
diff --git a/Blather.py b/Blather.py
index f5d8a67..6ec6b02 100755
--- a/Blather.py
+++ b/Blather.py
@@ -34,7 +34,7 @@ class Blather:
 		self.continuous_listen = False
 		self.commands = {}
 		self.read_commands()
-		self.recognizer = Recognizer(lang_file, dic_file)
+		self.recognizer = Recognizer(lang_file, dic_file, opts.microphone )
 		self.recognizer.connect('finished',self.recognizer_finished)
 
 		if opts.interface != None:
@@ -155,6 +155,9 @@ if __name__ == "__main__":
 	parser.add_option("-H", "--history", type="int",
 		action="store", dest="history",
 		help="number of commands to store in history file")
+	parser.add_option("-m", "--microphone", type="int",
+		action="store", dest="microphone", default=None,
+		help="Audio input card to use (if other than system default)")
 
 	(options, args) = parser.parse_args()
 	#make our blather object
diff --git a/README b/README
index a4a47d7..b88048d 100644
--- a/README
+++ b/README
@@ -1,9 +1,9 @@
 #Blather
-Blather is a speech recognizer that will run commands when a user speaks preset sentences. 
+Blather is a speech recognizer that will run commands when a user speaks preset sentences.
 
 ##Requirements
-1. pocketsphinx	
-2. gstreamer (and what ever plugin has pocket sphinx support)  
+1. pocketsphinx
+2. gstreamer (and what ever plugin has pocket sphinx support)
 3. pyside (only required for the Qt based UI)
 4. pygtk (only required for the Gtk based UI)
 
@@ -17,13 +17,22 @@ Blather is a speech recognizer that will run commands when a user speaks preset
 6. run Blather.py
     * 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 start a UI in 'continuous' listen mode, use the -c flag
+    * to use a microphone other than the system default, use the -d flag
 7. start talking
 
 ####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.
 
-**Example**  
-To run blather with the GTK UI and start in continuous listen mode:   
-./Blather.py -i g -c
\ No newline at end of file
+####Examples
+To run blather with the GTK UI and start in continuous listen mode:
+./Blather.py -i g -c
+
+To run blather with no UI and using a USB microphone recognized and device 2:
+./Blather.py -d 2
+
+####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`
+* `arecord -l`
\ No newline at end of file
diff --git a/Recognizer.py b/Recognizer.py
index 8497839..26ccd80 100755
--- a/Recognizer.py
+++ b/Recognizer.py
@@ -16,11 +16,16 @@ class Recognizer(gobject.GObject):
 	__gsignals__ = {
 		'finished' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING,))
 	}
-	def __init__(self, language_file, dictionary_file):
+	def __init__(self, language_file, dictionary_file, src = None):
 		gobject.GObject.__init__(self)
 		self.commands = {}
+		if src:
+			audio_src = 'alsasrc device="hw:%d,0"' % (src)
+		else:
+			audio_src = 'autoaudiosrc'
+
 		#build the pipeline
-		cmd = 'autoaudiosrc ! audioconvert ! audioresample ! vader name=vad ! pocketsphinx name=asr ! appsink sync=false'
+		cmd = audio_src+' ! audioconvert ! audioresample ! vader name=vad ! pocketsphinx name=asr ! appsink sync=false'
 		self.pipeline=gst.parse_launch( cmd )
 		#get the Auto Speech Recognition piece
 		asr=self.pipeline.get_by_name('asr')
@@ -31,10 +36,10 @@ class Recognizer(gobject.GObject):
 		#get the Voice Activity DEtectoR
 		self.vad = self.pipeline.get_by_name('vad')
 		self.vad.set_property('auto-threshold',True)
-		
+
 	def listen(self):
 		self.pipeline.set_state(gst.STATE_PLAYING)
-		
+
 	def pause(self):
 		self.vad.set_property('silent', True)
 		self.pipeline.set_state(gst.STATE_PAUSED)
@@ -42,4 +47,4 @@ class Recognizer(gobject.GObject):
 	def result(self, asr, text, uttid):
 		#emit finished
 		self.emit("finished", text)
-		
+