Пример #1
0
def mainloop():
    #tts.speak('thomas')
    #return True

    buf_size = detector.detector.NumChannels() * detector.detector.SampleRate(
    ) * 5
    detector.ring_buffer._buf = collections.deque(maxlen=buf_size)
    snowboydecoder.play_audio_file()

    utt = asr.get_asr()
    print('asr results: ' + utt)
    response = brain.get_response(utt)
    if response.confidence < SCORE_THRE:
        response = query(utt)
    else:
        response = response.text
        print('bot results: ' + response)
    if response: tts.speak(response)
Пример #2
0
def process_utterance():
    print('#####################detected')

    detector.interrupted = True
    isTriggered = False
    utt = asr.get_asr()
    print('asr results: ' + utt)
    response = brain.get_response(utt)
    if response.confidence < SCORE_THRE:
        #unmatchaed. go to google
        response = query(utt)
        if response: tts.speak(response)
    else:
        response = response.text
        print('bot results: ' + response)
        cmd = utt.split()
        if len(cmd) > 1:
            #response with command
            eval(cmd[1])
            tts.speak(cmd[2])
        else:
            tts.speak(response)

    detector.interrupted = False
Пример #3
0
    stop_program = True

wakeup_model = 'resources/thomas.pmdl'

# capture SIGINT signal, e.g., Ctrl+C
signal.signal(signal.SIGINT, signal_handler)

# Initialize ThreadedDetector object and start the detection thread
detector = snowboythreaded.ThreadedDetector(wakeup_model, sensitivity=0.8)
detector.start()

detector.start_recog(detected_callback=triggered,sleep_time=0.03)

while 1:
    while(isTriggered):
        pass
    detector.interrupted = True
    isTriggered = False
    utt = asr.get_asr()
    print('asr results: ' + utt)
    response = brain.get_response(utt)
    if response.confidence < SCORE_THRE:
        response = query(utt)
    else:
        response = response.text
        print('bot results: ' + response)
    if response: tts.speak(response)

    detector.interrupted = False

threaded_detector.terminate()
Пример #4
0
    json_data = open(input_filename)
    output = open(output_filename, "w")
    parsed_data = byteify(json.load(json_data))
    number_of_questions = len(parsed_data)

    question_counter = 0
    answered = 0
    result_list = []
    print("question\t\tanswer")
    print('[', file=output)
    while question_counter < number_of_questions:
        questionText = parsed_data[question_counter]["qText"]
        questionAnswers = parsed_data[question_counter]["answers"]
        ID = parsed_data[question_counter]["qId"]
        result = q.query(questionText)
        if len(result) > 0:
            answered = answered + 1
            print(questionText + "\t" + ','.join(result))
        else:
            print(questionText + "\t" + "answer not found")
        d = {}
        d['qId'] = ID
        d['query'] = questionText
        d['answer'] = result
        if question_counter < number_of_questions - 1:
            print('  %s,' % (json.dumps(d, sort_keys=True), ), file=output)
        else:
            print('  %s' % (json.dumps(d, sort_keys=True), ), file=output)
        sleep(2)
        question_counter = question_counter + 1
Пример #5
0
            print "Ping stdout output:\n", e.output
        with sr.WavFile(WAV_FILE) as source:
            audio = r.record(source) # read the entire WAV file
        try:        
            str=r.recognize_google(audio,language = "ko-KR")
            print(str)
        except:
            print "can't understand"
        os.remove('out.wav')
        '''
        cmdln='./gtts_run.sh '
        cmdln = cmdln + '"네 알겠습니다."'
        # call external program ro take a picture
        subprocess.check_call([cmdln], shell=True)
        '''
        res = q.query(str.encode('euc-kr'))
        
        if len(res) > 0:
            res = res[0].decode('utf-8')
            print res
            cmdln='./gtts_run.sh '
            cmdln = cmdln + '"'+res+ '"'
            # call external program ro take a picture
            subprocess.check_call([cmdln], shell=True)
        else:
            print 'no results'

        #cmdln='./gtts_run.sh '
        #cmdln = cmdln + '"'+str+ '"'
        # call external program ro take a picture
        #subprocess.check_call([cmdln], shell=True)
Пример #6
0
    json_data = open(input_filename)
    output = open(output_filename, "w")
    parsed_data = byteify(json.load(json_data))
    number_of_questions = len(parsed_data)

    question_counter = 0
    answered = 0
    result_list = []
    print("question\t\tanswer")
    print('[', file=output)
    while question_counter < number_of_questions:
        questionText = parsed_data[question_counter]["qText"]
        questionAnswers = parsed_data[question_counter]["answers"]
        ID = parsed_data[question_counter]["qId"]
        result = q.query(questionText)
        if len(result) > 0:
            answered = answered + 1
            print(questionText+"\t"+','.join(result))
        else:
            print(questionText+"\t"+"answer not found")
        d = {}
        d['qId'] = ID
        d['query'] = questionText
        d['answer'] = result
        if question_counter < number_of_questions-1:
            print('  %s,' % (json.dumps(d, sort_keys=True),), file=output)
        else:
            print('  %s' % (json.dumps(d, sort_keys=True),), file=output)
        sleep(2)
        question_counter = question_counter+1