respeaker / respeaker_python_library

To build voice enabled objects/applications with Python and ReSpeaker
Apache License 2.0
149 stars 74 forks source link

how to know when mic.listen() is complete #5

Closed ghost closed 6 years ago

ghost commented 7 years ago

I am trying to work with the Alexa example code and keep running into trouble with working from the data the mic creates (I have removed some code to make is more compact here)

`if mic.wakeup(keyword='alexa'): logging.debug('wakeup')

        data = mic.listen()

        try:
            text = bing.recognize(data)
            if text:
                logging.debug('Recognized %s' % text)

            alexa.recognize(data)
        except Exception as e:
            logging.warn(e.message)`

seems that bing uses the (data) and when alexa goes to use the (data) it does not work and gives some error as nothing to work with

is there a way to wait for the mic.listen to complete before moving along in code??

I want to use bing to give me what was said, then pass the data to alexa to do its thing

i even tried using my own function to save the data to file data = mic.listen() savewav(data)

but this gives me some error about there being no length and the wave function crashes.

xiongyihui commented 7 years ago

mic.listen() returns a generator which can be used only once. In your case, you can convert the generator to a audio string first.

data = mic.listen()
data = b''.join(data)
text = bing.recognize(data)
alexa.recognize(data)
ghost commented 7 years ago

did not work.. bing could recognise the text, but alexa voice service just gets stuck

INFO:mic:Detected alexa DEBUG:root:wakeup INFO:mic:Start listening INFO:mic:Stop listening DEBUG:requests.packages.urllib3.connectionpool:"POST /recognize/query?sblahblah…. HTTP/1.1" 200 None DEBUG:root:Recognized what is the time INFO:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): api.amazon.com DEBUG:requests.packages.urllib3.connectionpool:"POST /auth/o2/token HTTP/1.1" 200 977 INFO:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): access-alexa-na.amazon.com DEBUG:root:Start sending speech to Alexa Voice Service

at this point 3 green LEDs just track around and alexa never talks, and nothing moves past this point

xiongyihui commented 7 years ago

Updated https://github.com/respeaker/Alexa, it should work now