コード例 #1
0
def main():
    logging.basicConfig(level=logging.DEBUG)

    src = Source(rate=16000, channels=8)
    ch1 = ChannelPicker(channels=8, pick=1)
    ns = NS(rate=16000, channels=1)
    kws = KWS(model='alexa')
    doa = DOA(rate=16000)
    alexa = Alexa()

    src.link(ch1)
    ch1.link(ns)
    ns.link(kws)
    kws.link(alexa)

    src.link(doa)

    def on_detected(keyword):
        logging.info('detected {} at direction {}'.format(
            keyword, doa.get_direction()))
        alexa.listen()

    kws.set_callback(on_detected)

    src.recursive_start()

    while True:
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            break

    src.recursive_stop()
コード例 #2
0
ファイル: kws_cch.py プロジェクト: zxp36/VoiceReplayAttack
def main():
    src = Source(rate=16000, channels=4)
    ch1 = ChannelPicker(channels=4, pick=1)
    kws = KWS()
    doa = DOA(rate=16000)
    src.link(ch1)
    ch1.link(kws)
    src.link(doa)
    outf = "./log/test.wav"
    fsall = FileSink(outf, rate=16000, channels=4)
    src.link(fsall)
    #ch1.link(fs)
    for i in range(4):
        ch = ChannelPicker(channels=4, pick=i)
        src.link(ch)
        outf = "./log/test"+str(i)+".wav"
        fs = FileSink(outf, rate=16000, channels=1)
        ch.link(fs)


    def on_detected(keyword):
         print('detected {} at direction {}'.format(keyword, doa.get_direction()))

    kws.set_callback(on_detected)

    src.recursive_start()
    sec = 0
    while sec < 5:
        try:
            time.sleep(1)
            sec = sec + 1
        except KeyboardInterrupt:
            break

    src.recursive_stop()
コード例 #3
0
def main():
    src = Source(rate=16000, channels=8)
    ch1 = ChannelPicker(channels=8, pick=1)
    ns = NS(rate=16000, channels=1)
    kws = KWS()
    doa = DOA(rate=16000)

    src.link(ch1)
    ch1.link(ns)
    ns.link(kws)
    src.link(doa)

    def on_detected(keyword):
        print('detected {} at direction {}'.format(keyword,
                                                   doa.get_direction()))

    kws.set_callback(on_detected)

    src.recursive_start()

    while True:
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            break

    src.recursive_stop()
コード例 #4
0
def main():
    if len(sys.argv) < 2:
        print('Usage: {} audio.wav')
        sys.exit(1)

    src = Source(sys.argv[1])
    ch0 = ChannelPicker(channels=src.channels, pick=0)
    kws = KWS()
    doa = DOA(rate=16000)

    src.link(ch0)
    ch0.link(kws)
    src.link(doa)

    def on_detected(keyword):
        print('detected {} at direction {}'.format(keyword, doa.get_direction()))

    kws.set_callback(on_detected)

    src.recursive_start()
    while src.is_active():
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            break

    src.recursive_stop()

    # wait a second to allow other threads to exit
    time.sleep(1)
コード例 #5
0
ファイル: kws_doa.py プロジェクト: wbaiyu/avs
def main():
    src = Source(rate=16000, channels=4)
    ch0 = ChannelPicker(channels=src.channels, pick=0)
    kws = KWS(model='snowboy', sensitivity=0.6, verbose=True)
    doa = DOA(rate=16000)

    src.link(ch0)
    ch0.link(kws)
    src.link(doa)

    def on_detected(keyword):
        print('detected {} at direction {}'.format(keyword,
                                                   doa.get_direction()))

    kws.set_callback(on_detected)

    src.recursive_start()
    while True:
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            break

    src.recursive_stop()

    # wait a second to allow other threads to exit
    time.sleep(1)
コード例 #6
0
def main():
    logging.basicConfig(level=logging.DEBUG)

    src = Source(rate=16000, channels=8)
    ch1 = ChannelPicker(channels=8, pick=1)
    ns = NS(rate=16000, channels=1)
    kws = KWS(model='alexa')
    doa = DOA(rate=16000)

    src.link(ch1)
    ch1.link(ns)
    ns.link(kws)

    src.link(doa)

    def on_detected(keyword):
        direction = doa.get_direction()
        logging.info('detected {} at direction {}'.format(keyword, direction))
        pixels.wakeup(direction)

    kws.on_detected = on_detected

    src.recursive_start()

    while True:
        try:
            time.sleep(0.05)
            #direction = doa.get_direction()
            #logging.info('direction {}'.format(direction))
            #pixels.wakeup(direction)
        except KeyboardInterrupt:
            break

    src.recursive_stop()
コード例 #7
0
ファイル: kws_doa.py プロジェクト: kfxiaoyikeji/xyrobot
def main():
    src = Source(rate=16000, channels=4, frames_size=320)
    ch1 = ChannelPicker(channels=4, pick=1)
    kws = KWS()
    doa = DOA(rate=16000)

    src.link(ch1)
    ch1.link(kws)
    src.link(doa)

    def on_detected(keyword):
        position = doa.get_direction()
        pixels.wakeup(position)
        print('detected {} at direction {}'.format(keyword, position))

    kws.set_callback(on_detected)

    src.recursive_start()

    while True:
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            print('STOP')
            break

    src.recursive_stop()
コード例 #8
0
ファイル: doa.py プロジェクト: otoshuki/Raman-TheVisionBot
def main():
    ard = serial.Serial('/dev/ttyACM0', 9600)
    src = Source(rate=16000, channels=8)
    ch1 = ChannelPicker(channels=8, pick=1)
    kws = KWS()
    doa = DOA(rate=16000)
    time.sleep(1)

    src.link(ch1)
    ch1.link(kws)
    src.link(doa)

    while True:

        def on_detected(keyword):
            direction = doa.get_direction()
            print('detected {} at direction {}'.format(keyword, ))
            if (direction >= 0) and (direction <= 180):
                ard.write(struct.pack('>B', direction))

    kws.set_callback(on_detected)

    src.recursive_start()
    while True:
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            break

    src.recursive_stop()
コード例 #9
0
def main():
    src = Source(rate=16000, channels=4, frames_size=320)
    ch0 = ChannelPicker(channels=4, pick=0)
    kws = KWS(model='snowboy', sensitivity=0.6, verbose=True)
    doa = DOA(rate=16000)

    src.link(ch0)
    ch0.link(kws)
    src.link(doa)

    def on_detected(keyword):
        position = doa.get_direction()
        pixels.wakeup(position)
        print('detected {} at direction {}'.format(keyword, position))

    kws.set_callback(on_detected)

    src.recursive_start()
    while True:
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            break

    src.recursive_stop()
コード例 #10
0
ファイル: kws_doa.py プロジェクト: yhung219/HearingLoss
def main():
    src = Source(rate=16000, channels=4, frames_size=320)
    ch1 = ChannelPicker(channels=4, pick=1)
    kws = KWS(model='dad.pmdl')
    doa = DOA(rate=16000)

    src.link(ch1)
    ch1.link(kws)
    src.link(doa)

    def on_detected(keyword):
        position = doa.get_direction()
        pixels.wakeup(position)
        print('detected {} at direction {}'.format(keyword, position))

    kws.set_callback(on_detected)

    src.recursive_start()
    while True:
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            break

    src.recursive_stop()
コード例 #11
0
ファイル: callup.py プロジェクト: Knightsll/EEM
def main():
##    RESPEAKER_RATE = 16000
##    RESPEAKER_CHANNELS = 1
##    RESPEAKER_WIDTH = 2
##    CHUNK = 1024
##    RECORD_SECONDS = 2
    src = Source(rate=16000, channels=4, frames_size=320)
    ch1 = ChannelPicker(channels=4, pick=1)
    kws = KWS()
    doa = DOA(rate=16000)

    src.link(ch1)
    ch1.link(kws)
    src.link(doa)
    



    def on_detected(keyword):
        position = doa.get_direction()
        pixels.wakeup(position)
        print('detected {} at direction {}'.format(keyword, position))
        src.stream.start()
        print("* recording")
        frames = []
        for i in range(0, int(RESPEAKER_RATE / CHUNK * RECORD_SECONDS)):
            data = stream.read(CHUNK)
            frames.append(data)
        print("* done recording")
        src.stream.stop()
        print("start to send to baidu")
        # audio_data should be raw_data
        text = baidu.server_api(generator_list(frames))
        if text:
            try:
                text = json.loads(text)
                for t in text['result']:
                    print(t)
            except KeyError: 
                print("get nothing")
        else:
            print("get nothing")
            
        
        

    kws.set_callback(on_detected)

    src.recursive_start()
    while True:
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            break

    src.recursive_stop()
コード例 #12
0
def t3_bot():
    src = Source(rate=16000, channels=4, frames_size=320)
    ch1 = ChannelPicker(channels=4, pick=1)
    kws = KWS()
    doa = DOA(rate=16000)

    src.link(ch1)
    ch1.link(kws)
    src.link(doa)
    pixels.listen()
    pwm.setPWM(0, 0, 370)
    pwm.setPWM(1, 0, 640)

    counter = 0

    def on_detected(keyword):
        position = doa.get_direction()
        pixels.wakeup(position)
        print('detected {} at direction {}'.format(keyword, position))
        if position >= 30 and position <= 180:
            pwm.setPWM(0, 0, 175)
            pwm.setPWM(1, 0, 500)
        elif position > 180 and position <= 330:
            pwm.setPWM(0, 0, 560)
            pwm.setPWM(1, 0, 500)
        elif position > 330 or position < 30:
            pwm.setPWM(0, 0, 370)
            pwm.setPWM(1, 0, 6200)
        else:
            pwm.setPWM(0, 0, 370)
            pwm.setPWM(1, 0, 640)

        #talkassist.os.system("espeak 'may i help you'")
        print("How may I help you?")
        print("call google assistant here, delete this line.")

    kws.set_callback(on_detected)

    src.recursive_start()

    while True:
        try:
            time.sleep(1)
            counter += 1
            print("counter is at " + str(counter))
        except KeyboardInterrupt:
            break

    src.recursive_stop()
コード例 #13
0
def main():
    ser = serial.Serial("/dev/ttyACM0", 9600)

    src = Source(rate=16000, channels=4, frames_size=320)
    ch1 = ChannelPicker(channels=4, pick=1)
    kws = KWS(model='dad.pmdl')
    doa = DOA(rate=16000)

    src.link(ch1)
    ch1.link(kws)
    src.link(doa)

    def on_detected(keyword):
        position = doa.get_direction()
        pixels.wakeup(position)
        print('detected {} at direction {}'.format(keyword, position))
        if position <= 90:
            ser.write(b"1000\n")
        elif position > 90 and position <= 180:
            ser.write(b"0100\n")
        elif position > 180 and position <= 270:
            ser.write(b"0010\n")
        else:
            ser.write(b"0001\n")

        vibrate_time = 0.5
        time.sleep(vibrate_time)
        ser.write(b"0000\n")

    kws.set_callback(on_detected)

    src.recursive_start()
    while True:
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            break

    src.recursive_stop()
    ser.close()
コード例 #14
0
def main():
    logging.basicConfig(level=logging.DEBUG)

    src = Source(rate=16000, channels=4)
    ch1 = ChannelPicker(channels=4, pick=1)
    ns = NS(rate=16000, channels=1)
    kws = KWS(model='snowboy')
    doa = DOA(rate=16000)
    alexa = Alexa()

    alexa.state_listener.on_listening = pixels.listen
    alexa.state_listener.on_thinking = pixels.think
    alexa.state_listener.on_speaking = pixels.speak
    alexa.state_listener.on_finished = pixels.off

    def on_detected(keyword):
        direction = doa.get_direction()
        logging.info('detected {} at direction {}'.format(keyword, direction))
        pixels.wakeup(direction)
        alexa.listen()

    kws.on_detected = on_detected

    src.link(ch1)
    ch1.link(ns)
    ns.link(kws)
    kws.link(alexa)

    src.link(doa)

    src.recursive_start()

    while True:
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            break

    src.recursive_stop()
コード例 #15
0
def main():
    logging.basicConfig(level=logging.DEBUG)

    src = Source(rate=16000, channels=4) 
    ch1 = ChannelPicker(channels=4, pick=1)
    ns = NS(rate=16000, channels=1)
    kws = KWS(model='snowboy')
    doa = DOA(rate=16000)
    alexa = Alexa()

    alexa.state_listener.on_listening = pixels.listen
    alexa.state_listener.on_thinking = pixels.think
    alexa.state_listener.on_speaking = pixels.speak
    alexa.state_listener.on_finished = pixels.off

    def on_detected(keyword):
        direction = doa.get_direction()
        logging.info('detected {} at direction {}'.format(keyword, direction))
        pixels.wakeup(direction)
        alexa.listen()

    kws.on_detected = on_detected

    src.link(ch1)
    ch1.link(ns)
    ns.link(kws)
    kws.link(alexa)

    src.link(doa)

    src.recursive_start()

    while True:
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            break

    src.recursive_stop()
コード例 #16
0
def main():
    src = Source(rate=16000, frames_size=320, channels=8)
    # ds = DelaySum(channels=8, frames_size=src.frames_size, max_offset=max_offset)
    ch0 = ChannelPicker(channels=src.channels, pick=0)
    kws = KWS()
    # doa = DOA(rate=16000, chunks=20)
    alexa = Alexa()

    # alexa.state_listener.on_listening = pixel_ring.listen
    # alexa.state_listener.on_thinking = pixel_ring.think
    # alexa.state_listener.on_speaking = pixel_ring.speak
    # alexa.state_listener.on_finished = pixel_ring.off

    src.link(ch0)
    ch0.link(kws)
    kws.link(alexa)

    # src.link(doa)

    def on_detected(keyword):
        # direction = doa.get_direction()
        alexa.listen()
        # pixel_ring.wakeup((direction + 0) % 360)
        # print('detected {} at direction {}'.format(keyword, direction))
        print('detected keyword')

    kws.on_detected = on_detected

    src.recursive_start()
    while True:
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            print('quit')
            break

    src.recursive_stop()
コード例 #17
0
ファイル: oldproject.py プロジェクト: ikheyfets/ODBot
def main():
    src = Source(rate=16000, channels=1, frames_size=21000)
    ch1 = ChannelPicker(channels=1, pick=1)
    # doa = DOA(rate=16000, chunks=3)

    model_path = get_model_path()

    config = Decoder.default_config()
    # config.set_string('-hmm', os.path.join(model_path, 'en-us'))
    # config.set_string('-lm', os.path.join(model_path, 'en-us.lm.bin'))

    config.set_string('-hmm', os.path.join(model_path, 'en-us'))
    config.set_string('-lm', '2823.lm')
    config.set_string('-verbose', 'False')
    config.set_string('-dict', '2823.dic')
    # config.set_string('-dict', os.path.join(model_path, 'cmudict-en-us.dict'))
    config.set_string('-kws', 'keyphrase.list')
    config.set_string('-logfn', '/dev/null')
    # config.set_string('-keyphrase', 'hey there')
    # config.set_float('-kws_threshold', 1e-30)
    sphinx = Sphinx(config)

    src.link(ch1)
    # src.link(doa)
    ch1.link(sphinx)

    graph = XMLParser(graph_file="basic.xml", debug=True).parse()
    arduino = serial.Serial('/dev/ttyACM0', 57600)
    arduino.timeout = 0.1


    # Check currnet state
    print("Current State: {}".format(graph.get_current_state().name))


    def on_graph_state_change():
        print("onStateChange()")
        # Runs through state responses
        print("\tNew Current State: {}".format(graph.state))
        print("\tExecuting responses for nextState...")

        if len(graph.state.get_responses()) > 0:
            print('Responses: {}'.format(len(graph.state.get_responses())))
            for response in graph.state.get_responses():
                print('\tRunning Response {}'.format(response))
                # do response action whether it has to do with moving motors, turning led, etc

                if response.typ == ResponseType.GO_TO_STATE:
                    graph.set_current_state(response.value)
                elif response.typ == ResponseType.LED:
                    pixels != null:
                        if response.value == 'listening':
                            pixels.think()
                        elif response.value == 'off':
                            pixels.off()
                        elif response.value == 'hello':
                            pixels.speak()
                        elif response.value == 'following':
                            pixels.following()
                        elif response.value == 'doa':
                            if mic != null:
                                pixels.wakeup(mic.direction)
                        else:
                            print("Unknown LED value: {} was found.".format(response.value))
                elif response.typ == ResponseType.MOTOR_MOVE:
                    if response.value == 'forward':
                        arduino.write("d:f;")
                    elif response.value == 'stop':
                        arduino.write("d:s;")
                elif response.typ == ResponseType.CAMERA_MOVE:
                    if response.value == 'doa':
                        if mic != null:
                            voice_direction = mic.direction
                            print "voice from " + str(voice_direction)
                            arduino_command = "m:" + str(voice_direction) + ";"
                            if voice_direction < 180:
                                #voice is coming from behind
                                voice_direction = (voice_direction + 180) % 360
                            else:
                                #voice is coming from in front
                                voice_direction = 90

                        arduino_command = arduino_command + "c:" + str(voice_direction) + ",120;"
                        arduino.write(arduino_command)
                        last_time_motor_moved = simpletime.time()
                        print("@done@")
                elif response.typ == ResponseType.VOICE_RESPONSE:
                    text = response.value.replace(' ', '_')

                    #Calls the Espeak TTS Engine to read aloud a Text
                    call([cmd_beg+cmd_out+text+cmd_end], shell=True)
                else:
                    print("Unused response type: {}.".format(response.typ))