nicholasjconn / python-alexa-voice-service

A Python implementation of Amazon's Alexa Voice Service.
MIT License
45 stars 17 forks source link

TypeError: Can't convert 'bytes' object to str implicitly #2

Open dly9014 opened 8 years ago

dly9014 commented 8 years ago

I'll go ahead and put this as a separate issue. I'm using python 3.5 as specified. I did google and find this that says "In Python 3, the socket returns data as bytes (it was string in Python 2)." which makes me think may be python version related, but that must not be the case because when I run main.py with python 2.7 it fails because no urllib.

Anyway below is what I got, any help is appreciated.

C:\Users\young_000\OneDrive\Code\Echo\python-alexa-voice-service>python main.py Press enter anytime to start recording (or 'q' to quit).Exception in thread Thread-1: Traceback (most recent call last): File "C:\Users\young_000\AppData\Local\Programs\Python\Python35-32\lib\threading.py", line 914, in bootstrap_inner self.run() File "C:\Users\young_000\AppData\Local\Programs\Python\Python35-32\lib\threading.py", line 862, in run self.target(self._args, *self._kwargs) File "C:\Users\young_000\OneDrive\Code\Echo\python-alexa-voice-service\alexa_device.py", line 181, in device_thread_function process_response_handle=self.process_response) File "C:\Users\young_000\OneDrive\Code\Echo\python-alexa-voice-service\alexa_communication.py", line 178, in __init self.init_connection() File "C:\Users\young_000\OneDrive\Code\Echo\python-alexa-voice-service\alexa_communication.py", line 200, in init_connection print("PUSH" + data.read()) TypeError: Can't convert 'bytes' object to str implicitly

You can start talking now... Traceback (most recent call last): File "main.py", line 45, in user_input_loop(alexa_device) File "main.py", line 30, in user_input_loop alexa_device.user_initiate_audio() File "C:\Users\young_000\OneDrive\Code\Echo\python-alexa-voice-service\alexa_device.py", line 203, in user_initiate_audio stream_id = self.alexa.start_recognize_event(raw_audio) AttributeError: 'NoneType' object has no attribute 'start_recognize_event'

nicholasjconn commented 8 years ago

I don't believe this code will work at all with Python 2.7, but I have not tested it.

Have you modified the code in any way? Or are you using it as-is?

You can try casting the "data.read()" part of the code to a string. This will allow the error to print out. When receiving a response code other than 204, there is an error. The purpose of line 200 is to print out the error in detail, allowing you to further debug it. Try the following for line 200:

print("PUSH " + str(data.read()))

dly9014 commented 8 years ago

Thanks. I haven't modified the code in any way, using it completely as is. I replace line 200 as suggested. Here's what I got:

C:\Users\young_000\OneDrive\Code\Echo\python-alexa-voice-service>python main.py Press enter anytime to start recording (or 'q' to quit).PUSHb'{"header":{"namespace":"System","name":"Exception","messageId":"327d2a3d-da8f-4347-9cf8-0582c5ad4706"},"payload":{"code":"INTERNAL_SERVICE_EXCEPTION","description":"Error reading entity from input stream."}}' Exception in thread Thread-1: Traceback (most recent call last): File "C:\Users\young_000\AppData\Local\Programs\Python\Python35-32\lib\threading.py", line 914, in _bootstrap_inner self.run() File "C:\Users\young_000\AppData\Local\Programs\Python\Python35-32\lib\threading.py", line 862, in run self._target(*self._args, **self._kwargs) File "C:\Users\young_000\OneDrive\Code\Echo\python-alexa-voice-service\alexa_device.py", line 181, in device_thread_function process_response_handle=self.process_response) File "C:\Users\young_000\OneDrive\Code\Echo\python-alexa-voice-service\alexa_communication.py", line 178, in __init__ self.init_connection() File "C:\Users\young_000\OneDrive\Code\Echo\python-alexa-voice-service\alexa_communication.py", line 201, in init_connection raise NameError("Bad status (%s)" % data.status) NameError: Bad status (500)

dly9014 commented 8 years ago

I tried this on a 2nd laptop from the ground up to see if I made a mistake somewhere. Got exactly the same error. I'm keen to get your code working as it looks like you are streaming audio inputs to AVS vs uploading a file all at one time.

Following the method here https://github.com/sammachin/AlexaCHIP/blob/master/main.py, voice response is very slow (5-10 seconds consistently). I see from this thread https://forums.developer.amazon.com/questions/10982/avs-takes-too-much-time-to-respond.html#answer-10984 that the recommended solution is to stream the audio to AVS to improve response time. Is that what you have done?

fenilgandhi commented 7 years ago

hi, i liked your code and was trying to make it run but unforunately it doesn't on my systems also . the problem seems that you have not set a "alexa" device in this line . File : alexa_device.py line 165 : self.alexa = None

the value of alexa is not set to some value here by you before referencing it . maybe you can set it to a proper value and get the thing working .`

meetri commented 7 years ago

i found a solution to this problem.

change line 407 in alexa_communication.py to: "context":[],

araghunatha2 commented 7 years ago

I too am getting the very same error and changing to "context":[] as suggested above didn't help, Anyone has other suggestions ?