Esempio n. 1
0
    def __init__(self, lisa_client, botname):
        # Init thread class
        threading.Thread.__init__(self)
        self._stopevent = threading.Event()

        configuration = ConfigManagerSingleton.get().getConfiguration()
        self.botname = lisa_client.botname.lower()
        self.scores = []
        self.record_time_start = 0
        self.record_time_end = 0
        self.wit_thread = None
        self.loop = None
        if configuration.has_key("keyword_score"):
            self.keyword_score = configuration['keyword_score']
        else:
            self.keyword_score = -10000

        # Build Gstreamer pipeline : mic->Pulse->tee|->queue->audioConvert->audioResample->vader->pocketsphinx->fakesink
        #                                           |->queue->audioConvert->audioResample->lamemp3enc->appsink
        # fakesink : async=false is mandatory for parallelism
        self.pipeline = gst.parse_launch('pulsesrc '
                                        #+ '! ladspa-gate Threshold=-30.0 Decay=2.0 Hold=2.0 Attack=0.1 '
                                        + '! tee name=audio_tee '
                                        + ' audio_tee. ! queue '
                                        + '            ! audioconvert ! audioresample '
                                        + '            ! audio/x-raw-int, format=(string)S16_LE, channels=1, rate=16000 '
                                        + '            ! lamemp3enc bitrate=64 mono=true '
                                        + '            ! appsink name=rec_sink emit-signals=true '
                                        + ' audio_tee. ! queue '
                                        + '            ! audioconvert ! audioresample '
                                        + '            ! vader name=vad_asr auto-threshold=true'
                                        + '            ! tee name=asr_tee '
                                        + '             asr_tee. ! fakesink async=false name=asr_sink'
                                        + '             asr_tee. ! pocketsphinx name=asr '
                                        + '                      ! fakesink async=false'
                                         )

        # Create recorder
        self.recorder = Recorder(lisa_client = lisa_client, listener = self)

        # Find client path
        if os.path.isdir('/var/lib/lisa/client/pocketsphinx'):
            client_path = '/var/lib/lisa/client/pocketsphinx'
        else:
            client_path = "%s/pocketsphinx" % PWD

        # PocketSphinx configuration
        asr = self.pipeline.get_by_name('asr')
        asr.set_property("dict", "%s/%s.dic" % (client_path, self.botname))
        asr.set_property("lm", "%s/%s.lm" % (client_path, self.botname))
        if configuration.has_key("hmm"):
            hmm_path = "%s/%s" % (client_path, configuration["hmm"])
            if os.path.isdir(hmm_path):
                asr.set_property("hmm", hmm_path)
        asr.connect('result', self._asr_result)
        asr.set_property('configured', True)
        self.ps = pocketsphinx.Decoder(boxed=asr.get_property('decoder'))

        # Start thread
        self.start()
Esempio n. 2
0
    def __init__(self):
        if self.__instance is not None:
            raise Exception("Singleton can't be created twice !")

        # Init thread class
        threading.Thread.__init__(self)
        self._stopevent = threading.Event()

        self.configuration = ConfigManagerSingleton.get().getConfiguration()

        self.queue = Queue([])
        self.lang = "en-EN"
        if self.configuration.has_key('lang'):
            self.lang = self.configuration['lang']
        if self.configuration.has_key("tts") == False or self.configuration["tts"].lower() == "pico"or self.configuration["tts"].lower() == "picotts":
            self.engine = "pico"
            self.ext = "wav"
        elif self.configuration["tts"].lower() == "voicerss" and "voicerss_key" in self.configuration:
            self.engine = "voicerss"
            self.ext = "ogg"
            self.voicerss_key = self.configuration["voicerss_key"]
        else:
            player.play_block("error_conf")
            return

        # Init pre-synthetized utterances
        self._init_sys_utterance()

        # Start thread
        threading.Thread.start(self)
Esempio n. 3
0
 def __init__(self):
     self.factory = None
     self.configuration = ConfigManagerSingleton.get().getConfiguration()
     self.listener = None
     self.debug_input = False
     self.debug_output = False
     if self.configuration.has_key("debug"):
         if self.configuration["debug"].has_key("debug_input"):
             self.debug_input = self.configuration["debug"]["debug_input"]
         if self.configuration["debug"].has_key("debug_output"):
             self.debug_output = self.configuration["debug"]["debug_output"]
     self.zone = ""
     if self.configuration.has_key("zone"):
         self.zone = self.configuration["zone"]
Esempio n. 4
0
def makeService(config):
    global LisaFactory

    # Get configuration
    if config["configuration"]:
        ConfigManagerSingleton.get().setConfiguration(config["configuration"])
    configuration = ConfigManagerSingleton.get().getConfiguration()

    # Check vital configuration
    if configuration.has_key("lisa_url") == False or configuration.has_key("lisa_engine_port_ssl") == False:
        Speaker.start()
        Speaker.speak("error_conf")
        return

    # Multiservice mode
    multi = service.MultiService()
    multi.setServiceParent(application)

    # Ctrl-C handler
    signal.signal(signal.SIGINT, sigint_handler)

    # Create factory
    LisaFactory = LisaClientFactory()
    LisaFactory.Init()

    # Start client
    if configuration.has_key("enable_secure_mode") and configuration["enable_secure_mode"] == True:
        lisaclientService = internet.TCPClient(
            configuration["lisa_url"], configuration["lisa_engine_port_ssl"], LisaFactory, CtxFactory()
        )
    else:
        lisaclientService = internet.TCPClient(
            configuration["lisa_url"], configuration["lisa_engine_port"], LisaFactory
        )
    lisaclientService.setServiceParent(multi)

    return multi
Esempio n. 5
0
    def __init__(self, lisa_client, listener):
        # Init thread class
        threading.Thread.__init__(self)
        self._stopevent = threading.Event()

        self.lisa_client = lisa_client
        self.configuration = ConfigManagerSingleton.get().getConfiguration()
        self.pipeline = listener.get_pipeline()
        self.capture_buffers = deque([])
        self.running_state = False
        self.wit = Wit(self.configuration['wit_token'])
        self.wit_confidence = 0.5
        if self.configuration.has_key('confidence'):
            self.wit_confidence = self.configuration['wit_confidence']
        self.record_time_start = 0
        self.record_time_end = 0

        # Get app sink
        self.rec_sink = self.pipeline.get_by_name('rec_sink')
        self.rec_sink.connect('new-buffer', self._capture_audio_buffer)

        # Configure vader
        # Using vader on pocketsphinx branch and not a vader on record branch,
        # because vader forces stream to 8KHz, so record quality would be worst
        vader = self.pipeline.get_by_name('vad_asr')
        vader.connect('vader-start', self._vader_start)
        vader.connect('vader-stop', self._vader_stop)

        # Get elements to connect/disconnect pockesphinx during record
        self.asr_tee = self.pipeline.get_by_name('asr_tee')
        self.asr_sink = self.pipeline.get_by_name('asr_sink')
        self.asr = self.pipeline.get_by_name('asr')
        self.asr_tee.unlink(self.asr_sink)

        # Start thread
        self.start()
Esempio n. 6
0
 def Init(self):
     self.configuration = ConfigManagerSingleton.get().getConfiguration()
Esempio n. 7
0
import threading
import os
import gettext
from lisa.client.lib import player
from Queue import Queue
from time import sleep
from subprocess import call
import urllib
from urllib import urlencode, urlopen
from random import randint
from twisted.python import log

soundfile = 'tts-output'
soundpath = '/tmp/'

configuration = ConfigManagerSingleton.get().getConfiguration()
path = '/'.join([ConfigManagerSingleton.get().getPath(), 'lang'])
_ = translation = gettext.translation(domain='lisa', localedir=path, fallback=True,
                                              languages=[configuration['lang'].split('-')[0]]).ugettext


# System utterance definition : key : {(weight1, message1), (weight2, message2)}
# Speaker will randomly choose a message in list, balanced by weights
_utterances = {
    'yes':             {(5, _("Yes ?")),
                        (1, _("I'm listening"))
                       },
    'error_conf':      {(1, _("My configuration file is not readable")),
                        (1, _("There's an error with my configuration file"))
                       },
    'not_understood':  {(1, _("I didn't understood your question")),