|
@@ -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
|
+
|