question

chris avatar image
chris asked

Getting a 500 error from alexa voice service(iOS APP)

Hi, I have an AVAudioRecorder which is recording the voice command, then Im converting it to nsdata using the following code - NSData *data = [NSData dataWithContentsOfURL:recorder.url]; Now I do a speech recongizer request using the following code - NSDictionary *headers = @{ @"Authorization": [NSString stringWithFormat:@"Bearer %@", authCode], @"Transfer-Encoding": @"chunked", @"Content-Type": @"multipart/form-data; boundary=someboundary" }; NSMutableData *postData = [[NSMutableData alloc] initWithData:[@"\r\n--someboundary\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; [postData appendData:[@"Content-Disposition: form-data; name=\"request\"\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; [postData appendData:[@"Content-Type: application/json; charset=UTF-8\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; [postData appendData:[@"{\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; [postData appendData:[@"\"messageHeader\": {\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; [postData appendData:[@"\"deviceContext\": [\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; [postData appendData:[@"{\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; [postData appendData:[@"\"name\": \"playbackState\",\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; [postData appendData:[@"\"namespace\": \"AudioPlayer\",\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; [postData appendData:[@"\"payload\": {\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; [postData appendData:[@"\"streamId\": \"\",\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; // what is the streamid supposed to be? [postData appendData:[@"\"offsetInMilliseconds\": \"\",\r\n" dataUsingEncoding:NSUTF8StringEncoding]];//Is this correct? [postData appendData:[@"\"playerActivity\": \"IDLE\"\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; [postData appendData:[@"}\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; [postData appendData:[@"}\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; [postData appendData:[@"]\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; [postData appendData:[@"},\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; [postData appendData:[@"\"messageBody\": {\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; [postData appendData:[@"\"profile\": \"alexa-close-talk\",\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; [postData appendData:[@"\"locale\": \"en-us\",\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; [postData appendData:[@"\"format\": \"audio/L16; rate=16000; channels=1\"\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; [postData appendData:[@"}\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; [postData appendData:[@"}\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; [postData appendData:[@"--someboundary\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; [postData appendData:[@"Content-Disposition: form-data; name=\"audio\"\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; [postData appendData:[@"Content-Type: audio/L16; rate=16000; channels=1\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; [postData appendData:[NSData dataWithData:audioData]]; [postData appendData:[[NSString stringWithFormat:@"\r\n--someboundry--"] dataUsingEncoding:NSUTF8StringEncoding]]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@" https://access-alexa-na.amazon.com/v1/avs/speechrecognizer/recognize"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20.0]; [request setHTTPMethod:@"POST"]; [request setAllHTTPHeaderFields:headers]; [request setHTTPBody:postData]; NSURLSession *session = [NSURLSession sharedSession]; NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { if (error) { NSLog(@"%@", error); } else { NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response; NSLog(@"SpeechRecognition %@", httpResponse); } }]; [dataTask resume]; But the above code is giving me a 500 error. Any help is greatly appreciated
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.

elstryan@Amazon avatar image
elstryan@Amazon answered
The one thing I spot is missing one \r\n around your audio data. [postData appendData:[@"Content-Type: audio/L16; rate=16000; channels=1\r\n\r\n" If this doesn't help you: To further debug would you mind trying the following: Make the request but commenting out the following line: //[postData appendData:[NSData dataWithData:audioData]]; And make sure that you get a 204 error (No content). Then we can narrow down what the problem by eliminating the audio bytes from the request. Also please make sure that you're audio recorder is setup for LPCM, 16K, 1 Channel. Message was edited by: elstryan@Amazon
1 comment
10 |5000

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

Hi Elstryan , thanks for your advice ,it helps!

I got the same response as Chris then i fellow your steps and i did get 204 error !

payload = {

code = "INTERNAL_SERVICE_EXCEPTION";

description = "org.apache.james.mime4j.io.MaxLineLimitException: Maximum line length limit exceeded";

};

But i can't find the problem of my audio format , could you help ?

Here is my audio format (in Object-C):

NSDictionary *info = @{

AVFormatIDKey:[NSNumbernumberWithInt:kAudioFormatLinearPCM],//音频格式

AVSampleRateKey:@16000,//采样率

AVNumberOfChannelsKey:@1,//声道数

AVLinearPCMBitDepthKey:@16,//采样位数

AVLinearPCMIsBigEndianKey:@NO,

AVLinearPCMIsFloatKey:@NO,

AVEncoderAudioQualityKey:[NSNumbernumberWithInt:AVAudioQualityMedium],

};

0 Likes 0 ·
Alain avatar image
Alain answered

seeking for help :(

anybody knows this response?

{

header = {

messageId = "58bcf077-7f0f-4ff9-b3b4-af6d00befe3c";

name = Exception;

namespace = System;

};

payload = {

code = "INTERNAL_SERVICE_EXCEPTION";

description = "org.apache.james.mime4j.io.MaxLineLimitException: Maximum line length limit exceeded";

};

}

2 comments
10 |5000

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

<NSHTTPURLResponse: 0x14edc45a0> { URL: https://avs-alexa-na.amazon.com/v20160207/events } { status code: 500, headers {

"Access-Control-Allow-Origin" = "*";

"Content-Type" = "application/json; charset=UTF-8";

"access-control-allow-headers" = "authorization,x-amz-access-token";

"x-amzn-requestid" = "129e40fffe1cc03f-00007a6c-000881ba-718cdbc612f9309c-1a8af04c-5-";

} }

0 Likes 0 ·

It looks like this is the same question addressed in this thread:

https://forums.developer.amazon.com/questions/36478/avs-response-with-status-code-500.html

0 Likes 0 ·