question

Sudhindra avatar image
Sudhindra asked

HTTP 500 or BAD Request on a .net client app

Hi Experts, I am trying to get a .net client to invoke alexa voice service. I tried using the sample reference app to invoke the [b]/speechrecognizer/recognize api[/b] So far, I have tried two approaches in the .net client code. 1. use a Stream Content and dump all content into a stream (like the java reference app/ sample app). This always results in a a bad request error. 2. Use a MultiPart form content and add string content and the media content and send the request. This results in a HTTP 500 error. from the service. I am not certain, what I am doing wrong here. any thoughts/ pointers ?
alexa voice service
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Eric@Amazon avatar image
Eric@Amazon answered
Can you supply us with examples of each type of request? As a general note, one possible cause of 500 errors is bad audio data. Make sure that the data you're sending to Alexa is 16kHz, mono PCM audio.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sudhindra avatar image
Sudhindra answered
Hi, I am not able to reproduce the Bad Request Error from my test console. But for the Internal Server error, I was able to get the following capture: [b]Begin Request[/b] POST https://access-alexa-na.amazon.com/v1/avs/speechrecognizer/recognize HTTP/1.1 Authorization: Bearer [i]OAuth Token[/i] Content-Type: multipart/form-data; boundary="1BOUNDARY1" Host: access-alexa-na.amazon.com Connection: Keep-Alive Content-Length: 76946 --1BOUNDARY1 Content-Type: application/json; charset=utf-8 Content-Disposition: form-data; name=request {"messageHeader": {"deviceContext": [{"name": "playbackState","namespace": "AudioPlayer","payload": {"streamId": "0","offsetInMilliseconds": "10","playerActivity": "IDLE"}}]},"messageBody": {"profile": "alexa-close-talk","locale": "en-us","format": "audio/L16; rate=16000; channels=1"}} --1BOUNDARY1 Content-Type: audio/L16; rate=16000; channels=1 Content-Disposition: form-data; name=audio [i]mono 16000 Hz 16bit PCM Audio file stream[/i] --1BOUNDARY1-- [b]End Request[/b] for this request I get a response : [b] Connection: keep-alive x-amzn-RequestId: 692d1313-63b5-11e5-a513-d39f82332c77 x-amzn-ErrorType: InternalServerError: https://developer.amazon.com/edw/home.html Vary: Accept-Encoding, User-Agent Date: Fri, 25 Sep 2015 18:44:11 GMT Server: Server {"error":{"code":"com.amazon.alexahttpproxy.exceptions.InternalServerError","message":"Request could not be executed due to an internal service error."}} [/b]
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sudhindra avatar image
Sudhindra answered
I also did log the entire request to text file and can share that too if required.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Eric@Amazon avatar image
Eric@Amazon answered
I think I see the problem. You're specifying the boundary as "\"1BOUNDARY1\"", instead of "1BOUNDARY1". In Content-type, it should be this: boundary=1BOUNDARY1 Did that fix it?
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

E. McDonald avatar image
E. McDonald answered
What happens if you set streamId to blank instead of 0? So "streamId": "" instead of "streamId": "0"
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Eric@Amazon avatar image
Eric@Amazon answered
Thanks E. McDonald - good catch. The streamId should be blank instead of 0.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

by LennySh avatar image
by LennySh answered
Can you post a sample of your code? I can't even get as far as you with .NET. I'm getting a Server Error 400 Bad Request.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

by LennySh avatar image
by LennySh answered
Ok, I'm now getting a response... Just having trouble understanding how to handle the response... Message was edited by: by LennySh
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

by LennySh avatar image
by LennySh answered
Nevermind, I finally figured out how to get the audio response and play it back.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

newalexadeveloper avatar image
newalexadeveloper answered
Just stumbled upon this thread. Can anyone share sample code for this in .NET?
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.