Esempio n. 1
0
def main():
    logging.basicConfig(level=logging.DEBUG)

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

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

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

    kws.set_callback(on_detected)

    src.recursive_start()

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

    src.recursive_stop()
Esempio n. 2
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()
Esempio n. 3
0
def main():
    src = Source(rate=16000, channels=2)
    route = Route(channels=src.channels)
    ns = NS(rate=16000, channels=1)

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

        return on_detected

    kws = []
    for channel in range(2):
        k = KWS(model='snowboy', sensitivity=0.6, verbose=False)
        k.on_detected = get_kws_callback(channel)
        
        kws.append(k)

    # data flow between elements
    # ---------------------------
    # src -> route -> ns -> kws[0]
    #           \
    #           kws[1]
    src.link(route)
    route.link((ns, kws[1]))
    ns.link(kws[0])

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

    src.recursive_stop()
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()
Esempio n. 5
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()
Esempio n. 6
0
class StateMachine:
    def __init__(self, wake_word_model):

        self.__src = Source(rate=16000)
        self.__ns = NS(rate=16000, channels=1)
        self.__kws = KWS(model=wake_word_model)
        self.__alexa = Alexa()

        self.__src.link(self.__ns)
        self.__ns.link(self.__kws)
        self.__kws.link(self.__alexa)

        self.__pixels = ThreePixels()
        self.__button = Button()

        self.__alexa.state_listener.on_listening = self.on_listening
        self.__alexa.state_listener.on_thinking = self.on_thinking
        self.__alexa.state_listener.on_speaking = self.on_speaking
        self.__alexa.state_listener.on_finished = self.on_finished

    def on_listening(self):
        self.__pixels.wakeup()

    def on_thinking(self):
        self.__pixels.think()

    def on_speaking(self):
        self.__pixels.speak()

    def on_finished(self):
        self.__pixels.off()

    def __on_detected(self, keyword):
        print('detected {}'.format(keyword))
        print('Alexa is listening!')
        self.__alexa.listen()

    def __pushed_button(self, channel):
        print('button pushed')
        print('Alexa is listening!')
        self.__alexa.listen()

    def start(self):
        print('starting voice engine')
        self.__kws.set_callback(self.__on_detected)
        Button.set_callback_on_rising(self.__pushed_button)
        self.__src.recursive_start()

    def stop(self):
        print('stopping voice engine')
        self.__src.recursive_stop()
        Button.clean_up()
        self.__pixels.off()
Esempio n. 7
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. 8
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. 9
0
def main():
    src = Source('/tmp/ec.output', rate=16000, channels=2)
    ch0 = ChannelPicker(channels=src.channels, pick=1)
    ns = NS()
    kws = KWS(model='alexa', sensitivity=0.7)
    alexa = Alexa()

    src.pipeline(ch0, ns, kws, alexa)

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

    kws.set_callback(on_detected)

    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

    src.pipeline_start()

    is_quit = []

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

    signal.signal(signal.SIGINT, signal_handler)

    while src.is_active() and not is_quit:
        time.sleep(1)

    src.pipeline_stop()
Esempio n. 10
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)
    ns = NS(rate=src.rate, channels=1)
    kws = KWS()

    src.pipeline(ch0, kws)

    # src.pipeline(ch0, 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)
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. 12
0
    def __init__(self, wake_word_model):

        self.__src = Source(rate=16000)
        self.__ns = NS(rate=16000, channels=1)
        self.__kws = KWS(model=wake_word_model)
        self.__alexa = Alexa()

        self.__src.link(self.__ns)
        self.__ns.link(self.__kws)
        self.__kws.link(self.__alexa)

        self.__pixels = ThreePixels()
        self.__button = Button()

        self.__alexa.state_listener.on_listening = self.on_listening
        self.__alexa.state_listener.on_thinking = self.on_thinking
        self.__alexa.state_listener.on_speaking = self.on_speaking
        self.__alexa.state_listener.on_finished = self.on_finished
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()
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()
Esempio n. 15
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. 16
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. 17
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. 18
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. 19
0
def main():
    src = Source(rate=16000, channels=1, device_name="default")
    ns = NS(rate=16000, channels=1)
    kws = KWS(model='computer', sensitivity=0.6, verbose=True)

    src.pipeline(ns, 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. 21
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()
    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. 22
0
 CTRL + C
'''


def CtrlC(signum, frame):
    os.kill(os.getpid(), signal.SIGKILL)


'''
 main  start ...
'''
if __name__ == "__main__":
    try:
        src = Source(channels=8)
        ch0 = ChannelPicker(channels=src.channels, pick=0)
        ns = NS()

        bing = Bing(BING_KEY)

        src.pipeline(ch0, ns, bing)

        bing_api_call()

        signal.signal(signal.SIGINT, CtrlC)
        signal.signal(signal.SIGTERM, CtrlC)

        thread_key = threading.Thread(target=key_hander, args=(1, ))
        thread_play = threading.Thread(target=pre_play, args=(1, ))

        thread_key.setDaemon(True)
        thread_play.setDaemon(True)
Esempio n. 23
0
import time
import signal
from voice_engine.source import Source
from voice_engine.kws import KWS
from voice_engine.ns import NS
from avs.alexa import Alexa

src = Source(rate=16000)
ns = NS(rate=16000, channels=1)
kws = KWS(model='/home/pi/coach/alexa.pmdl')
alexa = Alexa()

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


def on_detected(keyword):
    print('detected {}'.format(keyword))
    print('Alexa is listening!')
    alexa.listen()


kws.set_callback(on_detected)

is_quit = []


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