Exemplo n.º 1
0
def do_rec():

    global rec, stdscr, loc, hstr, prompt, recording, asr, options, mqtt_finalize, mqtt_cond, mqtt_audio, mqtt_listen

    logging.debug ('do_rec...')

    time.sleep(0.1)

    recording = []
    swin = misc.message_popup(stdscr, 'Recording...', 'Please speak now.')

    if options.mqtt:

        mqtt_cond.acquire()
        try:
            mqtt_finalize = False
            mqtt_listen   = True
            while not mqtt_finalize:
                mqtt_cond.wait()

                logging.debug ('do_rec... got audio from mqtt')
                recording.extend(mqtt_audio)

                hstr, confidence = asr.decode(SAMPLE_RATE, mqtt_audio, mqtt_finalize, stream_id=MQTT_LOCATION)

            logging.debug ('do_rec... mqtt listen loop done')
            mqtt_listen   = False
        finally:
            mqtt_cond.release()

    else:

        rec.start_recording(FRAMES_PER_BUFFER)

        finalize  = False

        while not finalize:

            samples = rec.get_samples()

            audio, finalize = vad.process_audio(samples)
            if not audio:
                continue

            recording.extend(audio)

            hstr, confidence = asr.decode(SAMPLE_RATE, audio, finalize, stream_id=loc)

        rec.stop_recording()

    prompt = hstr

    stdscr.refresh()
    swin = misc.message_popup(stdscr, 'Processing input...', prompt)

    do_process_input()
Exemplo n.º 2
0
def do_apply_solution (sidx):

    global stdscr, responses, kernal, cur_context, next_context

    if sidx >= len(responses):
        misc.message_popup(stdscr, 'Error', 'Solution #%d does not exist.' % sidx)
        stdscr.getch()
        return

    # apply DB overlay, if any
    ovl = responses[sidx][4].get(ASSERT_OVERLAY_VAR_NAME)
    if ovl:
        ovl.do_apply(AI_MODULE, kernal.db, commit=True)

    responses = []
    cur_context = next_context
Exemplo n.º 3
0
def do_help():

    global stdscr

    misc.message_popup(stdscr, 'Help', """
    simple question - response:

    "what are you called?",
    "I am called HAL 9000".

    context, patterns, variables::

    context(topic, wdeProgrammingLanguage),
    "what are you called (by the way|again|)?",
    or ( "I am called {self:rdfsLabel|en, s}",
         "My name is {self:rdfsLabel|en, s}").
    """)

    c = stdscr.getch()
Exemplo n.º 4
0
def do_save_audio ():

    global prompt, vf_login, rec_dir, recording, stdscr

    ds = datetime.date.strftime(datetime.date.today(), '%Y%m%d')
    audiodirfn = '%s/%s-%s-rec/wav' % (rec_dir, vf_login, ds)
    logging.debug('audiodirfn: %s' % audiodirfn)
    misc.mkdirs(audiodirfn)

    cnt = 0
    while True:
        cnt += 1
        audiofn = '%s/de5-%03d.wav' % (audiodirfn, cnt)
        if not os.path.isfile(audiofn):
            break

    logging.debug('audiofn: %s' % audiofn)

    # create wav file 

    wf = wave.open(audiofn, 'wb')
    wf.setnchannels(1)
    wf.setsampwidth(2)
    wf.setframerate(SAMPLE_RATE)

    packed_audio = struct.pack('%sh' % len(recording), *recording)
    wf.writeframes(packed_audio)
    wf.close()  

    # append etc/prompts-original file

    etcdirfn = '%s/%s-%s-rec/etc' % (rec_dir, vf_login, ds)
    logging.debug('etcdirfn: %s' % etcdirfn)
    misc.mkdirs(etcdirfn)

    promptsfn = '%s/prompts-original' % etcdirfn
    with codecs.open(promptsfn, 'a') as promptsf:
        promptsf.write('de5-%03d %s\n' % (cnt, prompt))

    misc.message_popup(stdscr, 'WAVE file written', audiofn)

    stdscr.getch()
Exemplo n.º 5
0
def do_align_module():

    global stdscr, match_module, kernal, prompt, lang

    misc.message_popup(stdscr, 'Align...',
                       'Matching prompt against existing utterances...')
    matches = kernal.align_utterances(lang=lang, utterances=[prompt])

    msg = u''

    for i, res in enumerate(matches[prompt]):
        sim, loc, utt = res
        msg += u'%d %s\n   %s\n\n' % (i, loc, utt)
        if i == 4:
            break

    msg += 'Please select 0-%d >' % i

    stdscr.refresh()
    misc.message_popup(stdscr, 'Alignment Results', msg)

    while True:
        c = stdscr.getch()
        if c == ord('0'):
            match_location = matches[prompt][0][1]
            break
        if c == ord('1'):
            match_location = matches[prompt][1][1]
            break
        if c == ord('2'):
            match_location = matches[prompt][2][1]
            break
        if c == ord('3'):
            match_location = matches[prompt][3][1]
            break
        if c == ord('4'):
            match_location = matches[prompt][4][1]
            break

    match_module = match_location.split(':')[0]
Exemplo n.º 6
0
                time.sleep(RETRY_DELAY)

        logging.debug ('connection to MQTT broker %s:%d ... connected.' % (broker_host, broker_port))

        mqtt_listen = False
        mqtt_cond   = Condition()

        client.loop_start()

    else:

        #
        # pulseaudio recorder
        #

        misc.message_popup(stdscr, 'Initializing...', 'Init Pulseaudio Recorder...')
        rec = PulseRecorder (source, SAMPLE_RATE, volume)
        paint_main()
        logging.debug ('PulseRecorder initialized.')

    #
    # pulseaudio player
    #

    misc.message_popup(stdscr, 'Initializing...', 'Init Pulseaudio Player...')
    player = PulsePlayer('Zamia AI Debugger')
    paint_main()
    logging.debug ('PulsePlayer initialized.')

    #
    # VAD