alexa-pi / AlexaChipDEPRECATED

DEPRECATED - Use https://github.com/alexa-pi/AlexaPi instead ... Code to turn a CHIP into an Alexa Client
https://github.com/alexa-pi/AlexaPi
MIT License
366 stars 73 forks source link

AttributeError: Wave_read instance has no attribute '__exit__' #4

Closed rileycrane closed 7 years ago

rileycrane commented 8 years ago

Hi,

I'm trying to get this working. I've done the hardware mod (is there a way to test if it's successful?). Every time I run main.py I hear "hello" and then when I connect together Pins 14 and 1 on U14 I get the following error:

Traceback (most recent call last):
  File "main.py", line 128, in <module>
    with wave.open('beep.wav', 'rb') as f:
AttributeError: Wave_read instance has no attribute '__exit__'

Any ideas would be appreciated. Also, I had problems installing alsa based on your instructions. I had to install mpg321 independently.

Thanks!

PantherTheCat commented 8 years ago

I am experincing the same issue as @rileycrane @NextThingCo commentor advised moving to python 3 instead may help, however when attempting to run main.py with python 3 i get an error that alsaaudio module is not found. I installed pip3 to run the install with pip3 which failed out stating that multiple items were not found.

"chip@chip:~/AlexaCHIP$ sudo pip3 install -r requirements.txt Downloading/unpacking Wave>=0.0.2 (from -r requirements.txt (line 1)) Downloading Wave-0.0.2.tar.gz Running setup.py (path:/tmp/pip-build-dol7oi7b/Wave/setup.py) egg_info for package Wave

package init file 'wave/__init__.py' not found (or not a regular file)
warning: no files found matching '*.gif' under directory 'doc'

Downloading/unpacking python-memcached>=1.50 (from -r requirements.txt (line 2)) Downloading python_memcached-1.57-py2.py3-none-any.whl Requirement already satisfied (use --upgrade to upgrade): requests>=2.4.3 in /usr/lib/python3/dist-packages (from -r requirements.txt (line 3)) Downloading/unpacking wsgiref>=0.1.2 (from -r requirements.txt (line 4)) Downloading wsgiref-0.1.2.zip Running setup.py (path:/tmp/pip-build-dol7oi7b/wsgiref/setup.py) egg_info for package wsgiref Traceback (most recent call last): File "", line 17, in File "/tmp/pip-build-dol7oi7b/wsgiref/setup.py", line 5, in import ez_setup File "/tmp/pip-build-dol7oi7b/wsgiref/ez_setup/init.py", line 170 print "Setuptools version",version,"or greater has been installed." ^ SyntaxError: Missing parentheses in call to 'print' Complete output from command python setup.py egg_info: Traceback (most recent call last):

File "", line 17, in

File "/tmp/pip-build-dol7oi7b/wsgiref/setup.py", line 5, in

import ez_setup

File "/tmp/pip-build-dol7oi7b/wsgiref/ez_setup/init.py", line 170

print "Setuptools version",version,"or greater has been installed."

                         ^

SyntaxError: Missing parentheses in call to 'print'


Cleaning up... Command python setup.py egg_info failed with error code 1 in /tmp/pip-build-dol7oi7b/wsgiref Storing debug log for failure in /root/.pip/pip.log"

tobiasboyd commented 8 years ago

I have been working on getting a cheap BT speaker/headset to act as the audio out/in, but if you haven't already, you might try switching from the jack to pins 10 and 12 on U14: http://docs.getchip.com/#pin-headers (to see if it's related to the cutting / soldering).

PantherTheCat commented 8 years ago

@tobiasboyd I am using 10 12, I also used the mic in/ hpcom as an attempt. I have run this on 2 different CHIPS now - one that was using the TRRS mod, which i reversed and then seutp the jack through the header pins. The second, I never did the mod, and used only the pins. (The second, gave me the same error once I ran the main.py and pressed the button/shorted GND - XPIO1)

I tried again using python 3, reinstalling everything Alsa & memcache specific for python 3 installation, while I no longer get the wave error, I get a new error stating

chip@chip:~/echo$ sudo python3 main.py Traceback (most recent call last): File "main.py", line 131, in audio += data TypeError: Can't convert 'bytes' object to str implicitly

tobiasboyd commented 8 years ago

@PantherTheCat : that error seems less mysterious, audio is implicitly cast to a str in line 126. Do you get the same error if that's audio = None ?

PantherTheCat commented 8 years ago

@tobiasboyd - I will see what happens when I try that modification. I have been working with another user who has made several code modifications that I was also going to attempt.

PantherTheCat commented 8 years ago

@tobiasboyd yes same error.

@jitto created a python 3 version that gets further. Although I still end with an error - Although the error is after the button is released, instead of on press - so that is progress :smile_cat:
https://github.com/jitto/AlexaCHIP

Traceback (most recent call last): File "main.py", line 119, in alexa() File "main.py", line 99, in alexa data = r.content.split(boundary.encode('utf-8')) UnboundLocalError: local variable 'boundary' referenced before assignment

https://bbs.nextthing.co/t/turning-the-chip-into-an-amazon-echo/1630/33?u=panther

PantherTheCat commented 8 years ago

Figured it out, the TRRS jack mod was not scored deep enough, so it was not recording. Everything working now.

al-jimenez commented 8 years ago

@PantherTheCat I am getting the same error. I am using a USB microphone numb and the TRRS jack for audio output. I would prefer not to modify and score the CHIP board. Is there a way of not getting this error if you DON'T modify the board? Python3, etc installed...

NOTE: I have audio capture working and audio output working with arecord/aplay, just get the same error when I run python main.py:

Traceback (most recent call last): File "main.py", line 119, in alexa() File "main.py", line 99, in alexa data = r.content.split(boundary.encode('utf-8')) UnboundLocalError: local variable 'boundary' referenced before assignment

I don't want to modify the board unless I have to.

Thanks

bugduino commented 8 years ago

I'm getting the same error with a bluetooth speaker/microphone, are there any progress?

zampy24 commented 8 years ago

I was having the same UnboundLocalError, and for me, it didn't seem to be related to the bit rate or other of some of the solutions out there. So, in main.py, I just put it in a Try block to handle the error and prevent it from crashing. Seems to be working so far... (note: having trouble with the indents....try: and except are at the same indent, everything else is the same, but pushed forward one indent)

try:
            data = r.content.split(boundary.encode('utf-8'))
            for d in data:
                    if (len(d) >= 1024):
                            audio = d.split(b'\r\n\r\n')[1]
            with open("response.mp3", 'wb') as f:
                    f.write(audio)
            os.system('mpg321 -q 1sec.mp3 response.mp3')
   except(UnboundLocalError):
            print('had an error')
            pass
renekliment commented 7 years ago

This project is now deprecated in favor of the new AlexaPi (https://github.com/alexa-pi/AlexaPi) which has all the features of this project and much more, such as:

Please switch over to the new project and if your issue persists there, file an issue in the new repo's issue tracker. Thank you.