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()
예제 #2
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()
예제 #3
0
def main():
    src = Source(rate=16000, frames_size=320, channels=4)
    ds = DelaySum(channels=4,
                  frames_size=src.frames_size,
                  max_offset=max_offset)
    kws = KWS()
    doa = DOA(rate=16000, chunks=20)

    src.link(ds)
    ds.link(kws)

    src.link(doa)

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

    kws.on_detected = on_detected

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

    src.recursive_stop()
예제 #4
0
def main():
    src = Source(rate=16000, channels=6, device_name='hw:1')
    route = Route(channels=src.channels)

    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)
        k.on_detected = get_kws_callback(channel)

        kws.append(k)

    sink = FileSink('c6.wav', rate=src.rate, channels=src.channels)

    src.pipeline(route, kws)
    src.link(sink)

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

    src.recursive_stop()
예제 #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()
예제 #6
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()
예제 #7
0
def main():
    logging.basicConfig(level=logging.DEBUG)

    src = Source(rate=16000)
    kws = KWS(model='alexa')
    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):
        logging.info('detected {}'.format(keyword))
        alexa.listen()

    kws.on_detected = on_detected

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

    src.recursive_start()

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

    src.recursive_stop()
예제 #8
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)
예제 #9
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)
def main():
    # src = Source(rate=16000, frames_size=320, channels=6)
    src = Source(rate=16000, frames_size=160, channels=6, device_name='hw:1')

    ch0 = ChannelPicker(channels=src.channels, pick=0)
    kws = KWS(model='snowboy', sensitivity=0.5)
    # 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))
        print('detected {} '.format(keyword))
        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():
    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()
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)
예제 #14
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()
예제 #15
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()
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)
예제 #17
0
파일: New_.py 프로젝트: Knightsll/EEM
RECORD_SECONDS = 2

APP_ID = '10783244'
API_KEY = 'GlQae1odOq3Y1w2wCpGBOI27'
SECRET_KEY = 'aeb8dc5f91cc18990a873edb294e6641'

aipSpeech = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
baidu = BaiduVoiceApi(appkey=API_KEY, secretkey=SECRET_KEY)


def generator_list(list):
    for l in list:
        yield l


def on_detected(keyword):
    print('found {}'.format(keyword))
    os.system('play turnon.mp3')


kws.on_detected = on_detected

kws.start()
src.start()
while True:
    try:
        time.sleep(1)
    except KeyboardInterrupt:
        break
kws.stop()
src.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()
예제 #19
0
def main(api_endpoint, credentials, project_id, device_model_id, device_id,
         device_config, lang, verbose, grpc_deadline, once, *args, **kwargs):
    """Samples for the Google Assistant API.

    Examples:
      Run the sample with microphone input and speaker output:

        $ python -m googlesamples.assistant

      Run the sample with file input and speaker output:

        $ python -m googlesamples.assistant -i <input file>

      Run the sample with file input and output:

        $ python -m googlesamples.assistant -i <input file> -o <output file>
    """
    # Setup logging.
    logging.basicConfig(level=logging.DEBUG if verbose else logging.INFO)

    # Load OAuth 2.0 credentials.
    try:
        with open(credentials, 'r') as f:
            credentials = google.oauth2.credentials.Credentials(token=None,
                                                                **json.load(f))
            http_request = google.auth.transport.requests.Request()
            credentials.refresh(http_request)
    except Exception as e:
        logging.error('Error loading credentials: %s', e)
        logging.error('Run google-oauthlib-tool to initialize '
                      'new OAuth 2.0 credentials.')
        sys.exit(-1)

    # Create an authorized gRPC channel.
    grpc_channel = google.auth.transport.grpc.secure_authorized_channel(
        credentials, http_request, api_endpoint)
    logging.info('Connecting to %s', api_endpoint)

    if not device_id or not device_model_id:
        try:
            with open(device_config) as f:
                device = json.load(f)
                device_id = device['id']
                device_model_id = device['model_id']
                logging.info("Using device model %s and device id %s",
                             device_model_id, device_id)
        except Exception as e:
            logging.warning('Device config not found: %s' % e)
            logging.info('Registering device')
            if not device_model_id:
                logging.error('Option --device-model-id required '
                              'when registering a device instance.')
                sys.exit(-1)
            if not project_id:
                logging.error('Option --project-id required '
                              'when registering a device instance.')
                sys.exit(-1)
            device_base_url = ('https://%s/v1alpha2/projects/%s/devices' %
                               (api_endpoint, project_id))
            device_id = str(uuid.uuid1())
            payload = {
                'id': device_id,
                'model_id': device_model_id,
                'client_type': 'SDK_SERVICE'
            }
            session = google.auth.transport.requests.AuthorizedSession(
                credentials)
            r = session.post(device_base_url, data=json.dumps(payload))
            if r.status_code != 200:
                logging.error('Failed to register device: %s', r.text)
                sys.exit(-1)
            logging.info('Device registered: %s', device_id)
            pathlib.Path(os.path.dirname(device_config)).mkdir(exist_ok=True)
            with open(device_config, 'w') as f:
                json.dump(payload, f)

    assistant = SampleAssistant(lang, device_model_id, device_id, grpc_channel,
                                grpc_deadline)

    src = Source(rate=16000, frames_size=1600)
    kws = KWS(model='snowboy', sensitivity=0.6)

    src.link(kws)
    kws.link(assistant)

    def on_keyword(keyword):
        print('detected')
        assistant.listen()

    quit_event = threading.Event()

    def on_interrupt(sig, frame):
        print('quit')
        quit_event.set()

    signal.signal(signal.SIGINT, on_interrupt)
    kws.on_detected = on_keyword

    assistant.start()
    kws.start()
    src.start()

    while not quit_event.is_set():
        time.sleep(1)

    src.stop()
    kws.stop()
    assistant.stop()