Exemplo n.º 1
0
add_utt("(hi|hello|ok) computer",             Intent.HELLO)
add_utt("switch (on|off) the (light|lights)", Intent.LIGHT)
add_utt("switch the (light|lights) (on|off)", Intent.LIGHT)
add_utt("switch (on|off) the (music|radio)",  Intent.RADIO)
add_utt("switch the (music|radio) (on|off)",  Intent.RADIO)

rec.start_recording()
print ("Please speak. (CTRL-C to exit)")

while True:
    samples = rec.get_samples()
    audio, finalize = vad.process_audio(samples)
    if not audio:
        continue

    user_utt, c = asr.decode(audio, finalize)
    print ("\r%s           " % user_utt, end='', flush=True)

    if finalize:
        print ()

        best_dist = ED_THRESHOLD
        intent = None
        for utt in utt_map:
            dist = edit_distance (tokenize (utt, lang='en'), 
                       tokenize (user_utt, lang='en'))
            if (dist<ED_THRESHOLD) and (dist<best_dist):
                best_dist = dist
                intent    = utt_map[utt]

        if intent == Intent.HELLO:
Exemplo n.º 2
0
            if msg_queue:
                data = msg_queue.pop(0)
        finally:
            msg_cond.release()

        if data:

            if data['topic'] == TOPIC_INPUT_AUDIO:

                audio = data['pcm']
                do_finalize = data['final']
                loc = data['loc']

                logging.debug('asr.decode...')
                hstr2, confidence = asr.decode(SAMPLE_RATE,
                                               audio,
                                               do_finalize,
                                               stream_id=loc)
                logging.debug('asr.decode...done')

                if do_finalize:

                    logging.info("asr: %9.5f %s" % (confidence, hstr))

                    if hstr2:

                        hstr = hstr2
                        astr = '...'
                        data = {}

                        data['lang'] = lang
                        data['utt'] = hstr
Exemplo n.º 3
0
#
# main
#

rec.start_recording()

print("Please speak.")

while True:

    samples = rec.get_samples()

    audio, finalize = vad.process_audio(samples)

    if not audio:
        continue

    logging.debug('decoding audio len=%d finalize=%s audio=%s' %
                  (len(audio), repr(finalize), audio[0].__class__))

    user_utt, confidence = asr.decode(audio, finalize, stream_id=STREAM_ID)

    #    print("\r%s                     " % user_utt)

    if finalize:
        print("\r%s                     " % user_utt)
        if findmathkeywords(user_utt):
            print(calculate(user_utt))
        if 'stop listening' in user_utt:
            break
Exemplo n.º 4
0
    rec.start_recording()

    finalize  = False
    recording  = []

    while not finalize:

        samples = rec.get_samples()

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

        recording.extend(audio)

        user_utt, confidence = asr.decode(audio, finalize)

        print "\r             \rYou: %s      " % user_utt,

        if finalize and not user_utt:
            finalize = False
            recording  = []

    logging.info ("conv_user: %s" % user_utt)

    rec.stop_recording()
    print

    # import pdb; pdb.set_trace()
    ai_utt, score, action = kernal.process_input(ctx, user_utt)
Exemplo n.º 5
0
chunks_length_ms = 30

chunks = make_chunks(audio_content, chunks_length_ms)

for samples in chunks:
    sample = samples.get_array_of_samples()
    sample = np.int16(sample)

    if len(sample) < 480 :
	add = np.zeros((480-len(sample),))
        add=np.int16(add)
	sample = np.concatenate((sample,add))

    #audio, finalize = vad.process_audio(sample)
    #if not audio:
    #    continue
    logging.debug ('decoding audio len=%d finalize=%s audio=%s' % (len(sample), repr(finalize), sample[0].__class__))
    
    user_utt, confidence = asr.decode(sample, finalize, stream_id=STREAM_ID)
    
    #print "\r%s                     " % user_utt,
    print "\r%s                     " % user_utt,
    if finalize:
        print "\r%s                     " % user_utt,
        print "New Utterance\n"
        vad = VAD(aggressiveness=aggressiveness)

print '\n \n \n'
print user_utt

Exemplo n.º 6
0
    rec.start_recording()

    finalize = False
    recording = []

    while not finalize:

        samples = rec.get_samples()

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

        recording.extend(audio)

        user_utt, confidence = asr.decode(audio, finalize)

        print "\r             \rYou: %s      " % user_utt,

        if finalize and not user_utt:
            finalize = False
            recording = []

    logging.info("conv_user: %s" % user_utt)

    rec.stop_recording()
    print

    # import pdb; pdb.set_trace()
    ai_utt, score, action = kernal.process_input(ctx, user_utt)
Exemplo n.º 7
0
    finalize = False
    recording = []

    while not finalize:

        samples = rec.get_samples()

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

        recording.extend(audio)

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

        print "\r             \rYou: %s      " % user_utt,

        if finalize and not user_utt:
            finalize = False
            recording = []

    logging.info("conv_user: %s" % user_utt)

    rec.stop_recording()
    print

    # import pdb; pdb.set_trace()
    score, resps, actions, solutions, current_ctx = kernal.process_input(