コード例 #1
0
def main():
    global mic, quit_event

    bing = BingVoice(BING_KEY)
    awake = False

    pa = pyaudio.PyAudio()
    mic = Microphone(pa)
    player = Player(pa)

    while not quit_event.is_set():
        if not awake:
            if mic.recognize(keyword='hey respeaker'):
                awake = True
                player.play(hi)
                continue
            else:
                break

        command = mic.recognize(max_phrase_ms=6000, max_wait_ms=6000)
        if command:
            print('recognized: ' + command)
            if command.find('play music') > 0:
                pass

        awake = False

    mic.close()
コード例 #2
0
def main():
    global mic, quit_event

    bing = BingVoice(BING_KEY)
    awake = False

    pa = pyaudio.PyAudio()
    mic = Microphone(pa)
    player = Player(pa)

    while not quit_event.is_set():
        if not awake:
            if mic.recognize(keyword='hey respeaker'):
                awake = True
                player.play(hi)
                continue
            else:
                break

        command = mic.recognize(max_phrase_ms=6000, max_wait_ms=6000)
        if command:
            print('recognized: ' + command)
            if command.find('play music') > 0:
                pass

        awake = False

    mic.close()
コード例 #3
0
def task(quit_event):
    mic = Microphone(quit_event=quit_event)

    while not quit_event.is_set():
        if mic.wakeup('respeaker'):
            print('Wake up')
            data = mic.listen()
            text = mic.recognize(data)
            if text:
                print('Recognized %s' % text)
コード例 #4
0
def main():
    global mic, quit_event

    bing = BingVoice(BING_KEY)
    awake = False

    pa = pyaudio.PyAudio()
    mic = Microphone(pa)
    player = Player(pa)

    while not quit_event.is_set():
        if not awake:
            if mic.recognize(keyword='hey respeaker'):
                awake = True
                player.play(hi)
                continue
            else:
                break

        data = b''.join(mic.listen())
        if data:
            # recognize speech using Microsoft Bing Voice Recognition
            try:
                text = bing.recognize(data, language='en-US')
                print('Bing:' + text.encode('utf-8'))
                tts_data = bing.synthesize('you said ' + text)
                player.play_raw(tts_data)

                if text.find('start recording') >= 0:
                    mic.record('record.wav')
                elif text.find('stop recording') >= 0:
                    mic.interrupt(stop_recording=True)
                elif text.find('play recording audio') >= 0:
                    player.play('record.wav')
            except UnknownValueError:
                print(
                    "Microsoft Bing Voice Recognition could not understand audio"
                )
            except RequestError as e:
                print(
                    "Could not request results from Microsoft Bing Voice Recognition service; {0}"
                    .format(e))
        else:
            print('no data')

        awake = False

    mic.close()
コード例 #5
0
ファイル: main.py プロジェクト: respeaker/respeaker_hi
def main():
    global mic, quit_event

    bing = BingVoice(BING_KEY)
    awake = False

    pa = pyaudio.PyAudio()
    mic = Microphone(pa)
    player = Player(pa)

    while not quit_event.is_set():
        if not awake:
            if mic.recognize(keyword='hey respeaker'):
                awake = True
                player.play(hi)
                continue
            else:
                break

        data = b''.join(mic.listen())
        if data:
            # recognize speech using Microsoft Bing Voice Recognition
            try:
                text = bing.recognize(data, language='en-US')
                print('Bing:' + text.encode('utf-8'))
                tts_data = bing.synthesize('you said ' + text)
                player.play_raw(tts_data)

                if text.find('start recording') >= 0:
                    mic.record('record.wav')
                elif text.find('stop recording') >= 0:
                    mic.interrupt(stop_recording=True)
                elif text.find('play recording audio') >= 0:
                    player.play('record.wav')
            except UnknownValueError:
                print("Microsoft Bing Voice Recognition could not understand audio")
            except RequestError as e:
                print("Could not request results from Microsoft Bing Voice Recognition service; {0}".format(e))
        else:
            print('no data')

        awake = False

    mic.close()
コード例 #6
0
ファイル: alexa.py プロジェクト: scolate/lede-source-17.01.2
def main(quit_event=None, lan='zh'):
    mic = Microphone(quit_event=quit_event, language=lan)
    from broker import ControllerBroker
    localBroker = ControllerBroker()
    localBroker.client.loop_start()
    alexa = Alexa(mic)
    alexa.get_token()

    os.system('aplay {}/hello.wav'.format(resources_path))

    logging.debug('start')
    while not quit_event.is_set():
        keyword = mic.wakeup(keywords=['ALEXA', 'GREEBLE'])
        logging.debug('Recognized %s' % keyword)
        if keyword and ('HELLO' in keyword and 'ALEXA' in keyword):
            logging.debug('wakeup Alexa')
            os.system('aplay {}/alexayes.wav'.format(resources_path))
            data = mic.listen()
            try:
                alexa.recognize(data)
            except Exception as e:
                logging.warn(e.message)
        elif keyword and ('HELLO' in keyword and 'GREEBLE' in keyword):
            logging.debug('wakeup Zhima')
            os.system('aplay {}/alexayes.wav'.format(resources_path))
            data = mic.listen()
            keyword = mic.recognize(data)
            #keyword = mic.detect()
            logging.debug('Get commands %s' % keyword)
            if keyword and localcommands(keyword, localBroker) == 0:
                os.system('aplay {}/alexaok.wav'.format(resources_path))
            else:
                os.system('aplay {}/error.wav'.format(resources_path))

    mic.close()
    localBroker.client.loop_stop()
    logging.debug('Mission completed')
コード例 #7
0
ファイル: demo.py プロジェクト: respeaker/respeaker_hi
spi.write('online\n')


def handle_int(sig, frame):
    global mission_completed, mic

    print('quit')
    mission_completed = True
    mic.interrupt(stop_listening=True, stop_recording=True)


signal.signal(signal.SIGINT, handle_int)

while not mission_completed:
    if not awake:
        if mic.recognize(keyword='hey respeaker'):
            spi.write('wakeup\n')
            awake = True
            player.play(hi)
        continue

    data = b''.join(mic.listen())
    if not data:
        break

    spi.write('wait\n')

    # recognize speech using Microsoft Bing Voice Recognition
    try:
        text = bing.recognize(data, language='en-US')
        spi.write('answer\n')
コード例 #8
0
spi.write('online\n')


def handle_int(sig, frame):
    global mission_completed, mic

    print('quit')
    mission_completed = True
    mic.interrupt(stop_listening=True, stop_recording=True)


signal.signal(signal.SIGINT, handle_int)

while not mission_completed:
    if not awake:
        if mic.recognize(keyword='hey respeaker'):
            spi.write('wakeup\n')
            awake = True
            player.play(hi)
        continue

    data = b''.join(mic.listen())
    if not data:
        break

    spi.write('wait\n')

    # recognize speech using Microsoft Bing Voice Recognition
    try:
        text = bing.recognize(data, language='en-US')
        spi.write('answer\n')