コード例 #1
0
    def __init__(self, device, callback, appName, recogPath='./'):

        #function reference to the callback we will use upon recognition completion
        try:
            self.setCallback(callback)
        except e:
            raise e

        #init custom app fields
        self.recogPath = recogPath

        if self.recogPath[len(self.recogPath) - 1] != "/":
            self.recogPath += "/"

        self.appName = appName

        #init speech recog pipeline
        gst.debug_set_active(True)
        print "================="
        print "start STT init"
        print "================="
        self.pipeline = gst.parse_launch(' ! '.join([
            'alsasrc device=hw:%d' % device, 'queue', 'audioconvert',
            'audioresample', 'queue', 'vader name=vader auto-threshold=true',
            'pocketsphinx name=asr', 'fakesink dump=1'
        ]))

        #get asr out of pipeline to specify functions for sphinx to send data to, as well as add the grammar file to improve recognition
        self.asr = self.pipeline.get_by_name("asr")

        dictFilePath = recogPath + appName + ".dic"

        if not os.path.isfile(dictFilePath):
            print "The dictionary file for your application could not be found, continuing with default pocketsphinx dictionary."
        else:
            self.asr.set_property("dict", dictFilePath)

        self.asr.connect("partial_result", self.asr_partial_result)
        self.asr.connect("result", self.asr_result)

        fsgPath = recogPath + appName + ".fsg"

        #test for .fsg grammar file existence, usually created automatically from MakeRecog.py
        self.test_fsg(fsgPath)

        #actually set fsg because it exists
        self.asr.set_property("fsg", fsgPath)
        self.asr.set_property("configured", True)

        self.bus = self.pipeline.get_bus()
        self.bus.add_signal_watch()
        self.bus.connect("message::application", self.app_msg)

        print "================="
        print "finish STT init"
        print "================="
コード例 #2
0
ファイル: record.py プロジェクト: quozl/record-activity
from instance import Instance
import utils
from tray import HTray
from mediaview import MediaView
import hw
from iconcombobox import IconComboBox

logger = logging.getLogger("record.py")
COLOR_BLACK = gdk.color_parse("#000000")
COLOR_WHITE = gdk.color_parse("#ffffff")

TIMER_VALUES = [0, 5, 10]
DURATION_VALUES = [2, 4, 6]
QUALITY_VALUES = ["low", "high"]

gst.debug_set_active(True)
gst.debug_set_colored(False)
if logging.getLogger().level <= logging.DEBUG:
    gst.debug_set_default_threshold(gst.LEVEL_WARNING)
else:
    gst.debug_set_default_threshold(gst.LEVEL_ERROR)


class Record(activity.Activity):
    def __init__(self, handle):
        super(Record, self).__init__(handle)
        self.props.enable_fullscreen_mode = False
        Instance(self)

        self.add_events(gtk.gdk.VISIBILITY_NOTIFY_MASK)
        self.connect("visibility-notify-event", self._visibility_changed)
コード例 #3
0
from model import Model
from button import RecdButton
import constants
from instance import Instance
import utils
from tray import HTray
from mediaview import MediaView
import hw
from iconcombobox import IconComboBox

logger = logging.getLogger('record.py')
COLOR_BLACK = gdk.color_parse('#000000')
COLOR_WHITE = gdk.color_parse('#ffffff')

gst.debug_set_active(True)
gst.debug_set_colored(False)
if logging.getLogger().level <= logging.DEBUG:
    gst.debug_set_default_threshold(gst.LEVEL_WARNING)
else:
    gst.debug_set_default_threshold(gst.LEVEL_ERROR)

class Record(activity.Activity):
    def __init__(self, handle):
        super(Record, self).__init__(handle)
        self.props.enable_fullscreen_mode = False
        Instance(self)

        self.add_events(gtk.gdk.VISIBILITY_NOTIFY_MASK)
        self.connect("visibility-notify-event", self._visibility_changed)