Esempio n. 1
0
def main():
    import time
    import datetime
    from voice_engine.source import Source
    from voice_engine.channel_picker import ChannelPicker
    from voice_engine.file_sink import FileSink

    src = Source(channels=2, rate=48000, frames_size=48000)
    chx = ChannelPicker(channels=src.channels, pick=0)
    thd = THD(1000, src.rate)

    filename = '2.94dB1KHz.' + datetime.datetime.now().strftime("%Y%m%d.%H:%M:%S") + '.wav'

    sink = FileSink(filename, channels=src.channels, rate=src.rate)

    src.link(sink)
    src.pipeline(chx, thd)

    src.pipeline_start()

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

    src.pipeline_stop()
Esempio n. 2
0
File: ns_kws.py Progetto: wbaiyu/avs
def main():
    src = Source(rate=16000, channels=2)
    ch1 = ChannelPicker(channels=2, pick=1)
    ns = NS(rate=16000, channels=1)
    kws = KWS(model='snowboy', sensitivity=0.6, verbose=True)

    src.pipeline(ch1, ns, kws)

    def on_detected(keyword):
        print('detected {}'.format(keyword))

    kws.set_callback(on_detected)

    src.pipeline_start()

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

    src.pipeline_stop()

    # wait a second to allow other threads to exit
    time.sleep(1)
Esempio n. 3
0
def main():
    import time
    from voice_engine.source import Source
    from voice_engine.kws import KWS

    src = Source(rate=16000, channels=2, frames_size=1600)
    route = Route(channels=src.channels)
    kws = []

    def gen(channel):
        def on_detected(keyword):
            print('detected at channel {}'.format(channel))

        return on_detected

    for ch in range(src.channels):
        k = KWS(sensitivity=0.5)
        k.set_callback(gen(ch))
        kws.append(k)

    src.pipeline(route, kws)

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

    src.pipeline_stop()
def main():
    src = Source(rate=16000, frames_size=320, channels=8)
    ec = EC(channels=src.channels, capture=0, playback=7)
    ns = NS(rate=src.rate, channels=1)
    kws = KWS()

    # data flow between elements
    # ---------------------------
    # src -> ec -> ns -> kws
    src.pipeline(ec, ns, kws)

    def on_detected(keyword):
        led.toggle()
        print('detected {}'.format(keyword))

    kws.on_detected = on_detected

    is_quit = []

    def signal_handler(sig, frame):
        is_quit.append(True)
        print('quit')

    signal.signal(signal.SIGINT, signal_handler)

    src.pipeline_start()
    while not is_quit:
        time.sleep(1)

    src.pipeline_stop()

    # wait a second to allow other threads to exit
    time.sleep(1)
    led.off()
Esempio n. 5
0
def main():
    logging.basicConfig(level=logging.DEBUG)

    src = Source(rate=16000)
    ns = NS(rate=16000, channels=1)
    kws = KWS(model='alexa')
    alexa = Alexa()

    src.pipeline(ns, kws, alexa)

    def on_detected(keyword):
        logging.info('detected {}'.format(keyword))
        alexa.listen()

    kws.set_callback(on_detected)

    src.pipeline_start()

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

    src.pipeline_stop()
Esempio n. 6
0
def main():
    src = Source(rate=16000, frames_size=320, channels=8)
    ch0 = ChannelPicker(channels=src.channels, pick=0)
    kws = KWS(model='snowboy', sensitivity=0.5)
    doa = DOA(rate=src.rate, chunks=20)

    src.pipeline(ch0, kws)

    src.link(doa)

    def on_detected(keyword):
        direction = doa.get_direction()
        print('detected {} at direction {}'.format(keyword, direction))
        pixel_ring.wakeup(direction)
        time.sleep(2)
        pixel_ring.off()

    kws.on_detected = on_detected

    is_quit = []

    def signal_handler(sig, frame):
        is_quit.append(True)
        print('quit')

    signal.signal(signal.SIGINT, signal_handler)

    src.pipeline_start()
    while not is_quit:
        time.sleep(1)

    src.pipeline_stop()
Esempio n. 7
0
def main():
    logging.basicConfig(level=logging.DEBUG)

    src = Source(rate=16000)
    ns = NS(rate=16000, channels=1)
    kws = KWS(model='alexa')
    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.pipeline(ns, kws, alexa)

    def on_detected(keyword):
        logging.info('detected {}'.format(keyword))
        alexa.listen()

    kws.set_callback(on_detected)

    is_quit = []
    def signal_handler(signal, frame):
        is_quit.append(True)
        print('Quit')
    signal.signal(signal.SIGINT, signal_handler)

    src.pipeline_start()
    while not is_quit:
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            break
    src.pipeline_stop()
Esempio n. 8
0
def main():
    import time
    from voice_engine.source import Source

    src = Source(rate=48000, channels=2, frames_size=4800)
    dbfs = DBFS(channels=src.channels)
    src.pipeline(dbfs)

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

    src.pipeline_stop()
Esempio n. 9
0
def main():
    from voice_engine.source import Source

    src = Source(rate=16000, channels=1)
    assistant = Mirror()

    src.pipeline(assistant)
    src.pipeline_start()

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

    src.pipeline_stop()
Esempio n. 10
0
def main():
    src = Source(rate=16000, frames_size=160, channels=2)
    ch0 = ChannelPicker(channels=src.channels, pick=0)
    ns = NS(rate=src.rate, channels=1)
    kws = KWS()
    doa = DOA(rate=16000, chunks=50)
    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

    # data flow between elements
    # ---------------------------
    # src -> ns -> kws -> alexa
    #    \
    #    doa
    src.pipeline(ch0, ns, kws, alexa)

    src.link(doa)

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

    kws.on_detected = on_detected

    is_quit = []

    def signal_handler(sig, frame):
        is_quit.append(True)
        print('quit')

    signal.signal(signal.SIGINT, signal_handler)

    src.pipeline_start()
    while not is_quit:
        time.sleep(1)

    src.pipeline_stop()
    pixel_ring.off()

    # wait a second to allow other threads to exit
    time.sleep(1)
Esempio n. 11
0
def main():
    import time
    from voice_engine.source import Source

    src = Source(rate=16000, channels=2, frames_size=1600)
    ec = EC(channels=src.channels, capture=0, playback=1)

    src.pipeline(ec)
    src.pipeline_start()

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

    src.pipeline_stop()
Esempio n. 12
0
def main():
    src = Source(rate=16000, frames_size=320, channels=8)
    ec = EC(channels=src.channels, capture=0, playback=7)
    ns = NS(rate=src.rate, channels=1)
    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.pipeline(ec, ns, kws, alexa)

    src.link(doa)

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

    kws.on_detected = on_detected

    is_quit = []

    def signal_handler(sig, frame):
        is_quit.append(True)
        print('quit')

    signal.signal(signal.SIGINT, signal_handler)

    src.pipeline_start()
    while not is_quit:
        time.sleep(1)

    src.pipeline_stop()
    pixel_ring.off()

    # wait a second to allow other threads to exit
    time.sleep(1)
Esempio n. 13
0
def main():
    src = Source(rate=16000, channels=1, device_name="default")
    kws = KWS(model='computer', sensitivity=0.6, verbose=True)

    src.pipeline(kws)

    def on_detected(keyword):
        print('\ndetected {}'.format(keyword))

    kws.set_callback(on_detected)

    src.pipeline_start()

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

    src.pipeline_stop()
def main():
    src = Source(rate=16000, frames_size=320, channels=8)
    ec = EC(channels=src.channels, capture=0, playback=7)
    ns = NS(rate=src.rate, channels=1)
    kws = KWS()
    doa = DOA(rate=16000, chunks=20)

    # data flow between elements
    # ---------------------------
    # src -> ec -> ns -> kws
    #    \
    #    doa
    src.pipeline(ec, ns, kws)
    src.link(doa)

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

    kws.on_detected = on_detected

    is_quit = []

    def signal_handler(sig, frame):
        is_quit.append(True)
        print('quit')

    signal.signal(signal.SIGINT, signal_handler)

    src.pipeline_start()
    while not is_quit:
        time.sleep(1)

    src.pipeline_stop()
    pixel_ring.off()

    # wait a second to allow other threads to exit
    time.sleep(1)
Esempio n. 15
0
def main():
    src = Source(rate=16000, channels=8, frames_size=1600)
    ec = EC(channels=src.channels, capture=0, playback=6)
    kws = KWS(sensitivity=0.7)

    def on_detected(keyword):
        global count
        count += 1
        print('detected {}'.format(keyword))

    kws.on_detected = on_detected

    src.pipeline(ec, kws)

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

    print('total = {}'.format(count))
    src.pipeline_stop()
Esempio n. 16
0
def main():
    src = Source(rate=16000, frames_size=320, channels=8)
    ch0 = ChannelPicker(channels=src.channels, pick=0)
    kws = KWS(model='alexa', sensitivity=0.8)
    doa = DOA(rate=src.rate, 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.pipeline(ch0, kws, alexa)

    src.link(doa)

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

    kws.on_detected = on_detected

    is_quit = []

    def signal_handler(sig, frame):
        is_quit.append(True)
        print('quit')

    signal.signal(signal.SIGINT, signal_handler)

    src.pipeline_start()
    while not is_quit:
        time.sleep(1)

    src.pipeline_stop()
def main():
    src = Source(rate=16000, frames_size=320, channels=8)
    ec = EC(channels=src.channels, capture=0, playback=7)
    # ns = NS(rate=src.rate, channels=1)
    kws = KWS(model='alexa')
    alexa = Alexa()

    alexa.state_listener.on_listening = led.on
    alexa.state_listener.on_finished = led.off

    #src.pipeline(ec, ns, kws, alexa)
    src.pipeline(ec, kws, alexa)

    def on_detected(keyword):
        led.on()
        print('detected {}'.format(keyword))
        alexa.listen()

    kws.on_detected = on_detected

    is_quit = []

    def signal_handler(sig, frame):
        is_quit.append(True)
        print('quit')

    signal.signal(signal.SIGINT, signal_handler)

    src.pipeline_start()
    while not is_quit:
        time.sleep(1)

    src.pipeline_stop()
    led.off()

    # wait a second to allow other threads to exit
    time.sleep(1)
Esempio n. 18
0
def main():
    logging.basicConfig(level=logging.DEBUG)

    src = Source(rate=16000, channels=4, device_name='default')
    ds = DelaySum(channels=src.channels)
    ns = NS(rate=16000, channels=1)
    kws = KWS(model='alexa')
    alexa = Alexa()

    alexa.state_listener.on_listening = leds_on
#     alexa.state_listener.on_thinking = pixel_ring.think
#     alexa.state_listener.on_speaking = pixel_ring.speak
    alexa.state_listener.on_finished = leds_off

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

    def on_detected(keyword):
        logging.info('\ndetected {}'.format(keyword))
        alexa.listen()

    kws.set_callback(on_detected)

    is_quit = []
    def signal_handler(sig, frame):
        is_quit.append(True)
        print('quit')
    signal.signal(signal.SIGINT, signal_handler)

    src.pipeline_start()
    while not is_quit:
        time.sleep(1)

    src.pipeline_stop()
Esempio n. 19
0
def main():
    from voice_engine.source import Source
    from voice_engine.ns import NS
    from bf import BF

    src = Source(rate=16000, channels=8)
    bf = BF()
    ns = NS()
    assistant = Mirror()

    src.pipeline(bf, ns, assistant)
    ns.link(alexa)

    src.pipeline_start()

    led.off()

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

    src.pipeline_stop()
Esempio n. 20
0
def main():
    src = Source(rate=48000,
                 channels=4,
                 device_name='voicen',
                 bits_per_sample=32)
    decoder = Decoder(channels=src.channels, select=0, bits_per_sample=32)

    def on_data(data):
        print([c for c in data])
        ssid_length = data[0]
        ssid = data[1:ssid_length + 1].tostring().decode('utf-8')
        password_length = data[ssid_length + 1]
        password = data[ssid_length + 2:ssid_length + password_length +
                        2].tostring().decode('utf-8')
        # print(u'SSID: {}\nPassword: {}'.format(ssid, password))

        cmd = 'mosquitto_pub -t /voicen/hey_wifi -m 2'
        os.system(cmd)

        if os.system('which nmcli >/dev/null') != 0:
            print('nmcli is not found')
            return

        cmd = 'nmcli device wifi rescan'
        os.system(cmd)

        cmd = u'nmcli connection delete "{}"'.format(ssid)
        os.system(cmd)

        cmd = u'nmcli device wifi connect "{}" password "{}"'.format(
            ssid, password)
        if os.system(cmd) != 0:
            print('Failed to connect the Wi-Fi network')
            return

        print('Wi-Fi is connected')
        ip_info = get_ip_info()
        if not ip_info:
            print('Not find any IP address')
            return

        print(ip_info)
        decoder.done = True

        cmd = 'mosquitto_pub -t /voicen/hey_wifi -m 3'
        os.system(cmd)

        channel = int((data[-1] << 8) + data[-2])
        payload = json.dumps({'id': channel, 'data': ip_info.decode()})
        message = encrypt(channel, data, payload.encode())
        if os.system('which mosquitto_pub >/dev/null') != 0:
            print('mosquitto_pub is not found')

        cmd = 'mosquitto_pub -h q.voicen.io -u mqtt -P mqtt -q 1 -t "/voicen/hey_wifi/{}" -m "{}"'.format(
            channel, message)
        print(cmd)
        for _ in range(3):
            if os.system(cmd) == 0:
                break
        else:
            print('Failed to send message to the web page')

        print('Done')
        cmd = 'mosquitto_pub -t /voicen/hey_wifi -m 4'
        os.system(cmd)

    decoder.on_data = on_data

    src.pipeline(decoder)
    src.pipeline_start()

    while not decoder.done:
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            print('exit')
            break

    src.pipeline_stop()
Esempio n. 21
0
logging.basicConfig(level=logging.WARNING)

src = Source(rate=16000)
kws = KWS(model='alexa', sensitivity=0.5)
alexa = Alexa()

src.pipeline(kws, alexa)


def on_detected(keyword):
    print('detected {}'.format(keyword))
    alexa.listen()


kws.set_callback(on_detected)

is_quit = []


def signal_handler(signal, frame):
    print('Quit')
    is_quit.append(True)


signal.signal(signal.SIGINT, signal_handler)

src.pipeline_start()
while not is_quit:
    time.sleep(1)
src.pipeline_stop()
def main():
    src = Source(rate=16000, frames_size=320, channels=8)
    ch0 = ChannelPicker(channels=src.channels, pick=0)
    kws = KWS(model='alexa', sensitivity=0.8)
    pws = KWS(model='/usr/share/respeaker/snowboy/resources/nivi.pmdl')

    def pwstest():
        print('calling Personal function')
        exit()

    doa = DOA(rate=src.rate, 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.pipeline(ch0, kws, alexa)

    src.pipeline(ch0, pws, doa)

    src.link(doa)

    def on_detected(keyword):
        print('ALEXA Testing fuction')
        direction = doa.get_direction()
        print('detected {} at direction {}'.format(keyword, direction))
        alexa.listen()
        pixel_ring.wakeup(direction)
        print('afteralexa')

    kws.on_detected = on_detected
    #pws.on_detected = on_detected
    print('afterkws before pws')

    #is_quit = []

    def on_detected(keyword):
        direction = doa.get_direction()
        print('PWS Testing')
        print('detected {} at direction {}'.format(keyword, direction))
        pwstest()
        #alexa.listen()
        pixel_ring.wakeup(direction)
        print('Personal function working')

    pws.on_detected = on_detected

    is_quit = []

    def signal_handler(sig, frame):
        is_quit.append(True)
        print('quit')

    signal.signal(signal.SIGINT, signal_handler)

    src.pipeline_start()
    while not is_quit:
        time.sleep(1)

    src.pipeline_stop()