question

chris avatar image
chris asked

Integrate Alexa Voice Services with existing iOS apps

Hi, We are trying to implement Alexa Voice Services into our iOS app. I have added the Amazon authentication code following the example code from here - http://login.amazon.com/ios#install_login_with_amazon_library I changed the scope to alexa:all . When I press login with Amazon, it opens up safari and asks the user to login in to the amazon account. After, I login it asks you to agree to some terms and tells that the app will have access to "Connectivity to Alexa so that you can interact with it using your voice". After I select "I agree" it takes me a screen where it says "We're sorry! An error occurred when we tried to process your request. Rest assured, we're already working on the problem and expect to resolve it shortly." I have set up the URL Types correctly because if I disagree to the terms it brings me back to the app. So, I dont know what is happening. 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
Hi wingoldriver, Thanks for your interest in AVS. When you authorize you have to add a few more pieces of information as well as specifying the scope (see the code below). From what I've read I'm assuming you want to use your iOS app to talk directly to Alexa Voice Service, for this case use the following code. - (IBAction)onLogInButtonClicked:(id)sender { NSArray *requestScopes = [NSArray arrayWithObjects:@"alexa:all", nil]; NSMutableDictionary *options = [[NSMutableDictionary alloc] init]; NSString* scopeData = [NSString stringWithFormat:@"{\"alexa:all\":{\"productID\":\"%@\"," "\"productInstanceAttributes\":{\"deviceSerialNumber\":\"%@\"}}}", productId, deviceSerialNumber]; options[kAIOptionScopeData] = scopeData; [AIMobileLib authorizeUserForScopes:requestScopes delegate:delegate options:options]; } Once you finish authorizing you should receive an access token which you can use to talk to AVS.
10 |5000

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

Prasenjit avatar image
Prasenjit answered
Hi AlexaTeam, I was directed here by one of your helpful staff members. So, I tried to modify the loginButton code but what I'm unable to understand are these two in the above code: [b]productId[/b] & [b]deviceSerialNumber[/b]. Truth be told AVS, ASK, Alexa - all these information is overwhelming me. What I'm not clear about once I get the token, how do I call Alexa service? Thank you for understanding as I'm not completely familiar with Java or Node.js
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
No problem. Hopefully I can explain them in a way that makes sense. Alexa - The voice assistant which allows you to listen to music, get the weather, etc. AVS - You get everything involved with talking to Alexa, minus saying "Alexa" to have it start listening to your voice ASK - This is the SDK to allow you to extend Alexa to do new cool things. Anything you build with ASK will automatically work on Echo / Fire TV and any future devices with Alexa in them (including AVS devices) LWA - Login With Amazon: the service used to authenticate users and generate access tokens for use with AVS There are 2 approaches to adding Alexa to your product. 1) You have a device (such as a smart speaker) that you want to add Alexa to. So, you build in support for AVS. Great! Now you need a way to authorize it and associate it with the user's account. This is the "companion app" approach. The companion app connects to your smart product and allows the user to login and authorize the speaker to use Alexa and connect to their Amazon account. 2) You don't have a device you need to authorize - instead you want to add Alexa to your iOS application. This is the "AVS app" approach. For #1, you will need the device to generate a code verifier, which it then passes to your iOS app, which then sends it to Login with Amazon. The code verifier is important because AVS needs to know that the iOS app is acting on behalf of another product, so the authorization code that it sends back to the iOS app really corresponds to this other device. That other device then uses the code verifier to prove that it is the device the iOS app was talking about, and it is now authorized to use AVS. As far as the Node.js service goes, that's simply acting as a simple web server used to authorize a device. It's essentially taking the place of the iOS app in this approach. For #2, you don't need to bother with any code verifier stuff. You have the product you want to use with AVS right in your hand. So, all you actually need from LWA is an access token. Ultimately, in order to use AVS you need an access token. LWA is used to acquire one, using one of the methods described above. The product ID and deviceSerialNumber are extra information that we need in order to generate an access token for you. When you go through the initial setup process, you will create a security profile and product Id associated with it. This will give you an API key. You'll use that API key in combination with the product ID and device serial number (in the scope data) to get the access token that you need to communicate with AVS. That access token will be used with *every* call to AVS. If it ever expires, you'll use the refresh token to generate a new access token. If you look at the AVS documentation, the HTTP header includes an 'Authorization: Bearer { {xxxxxx}}' header. Simply replace { {xxxxxxx}} with the access token you've retrieved from LWA. All calls to AVS are simple HTTP requests. You can use the sample reference app and the documentation to determine how to interpret Alexa's response. Hope that clears things up for you! Feel free to follow-up if things still don't make sense.
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
Oh, and to more explicitly answer your above question, the product id you create yourself when you go through the developer portal steps to create your AVS application. It can be found in the Registered Products table of your Alexa Developer Portal, under 'ID'. The device serial number is just a unique identifier. The only requirement is that it be different for each unique device.
10 |5000

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

Prasenjit avatar image
Prasenjit answered
Hi Eric, First of all thank you for answering my question with such depth and simplicity, now I'm able to make complete sense. Also I'd like to add you response had resulted me in reading through all the forum and also look up Alexa re:Invent youtube videos. Having said that I'm still experience problem to get the token back from AMZN. As directed I got the productID from the Registed Products (ID) column. I also followed along to build the codeChallengeS256 string by 1. Make a random string of length 128 => [A-Z][a-z][0-9]-_.~ 2. Hash this string by using Security Framework of iOS using CC_SHA256 3. NSData* sha256 = [inputString dataUsingEncoding:NSUTF8StringEncoding]; NSString *base64Enc = [sha256 base64EncodedStringWithOptions:0]; 4. Followed AppendiA to remove the unwanted characters But I'm getting this error in the console: Error:APIKey for the Application is invalid Please note I'm got the Key from Registered Product > Edit > Security Profile > iOS Settings > Key and copied that and pasted in the API (key) under info.plist I'm trying to publish this code on GitHub post some cleanup and thank you for understanding that I'm a novice at this and also beginning as an iOS developer. So, I also had one more question; once I get the token how do I call and send Alexa the voice ? I read the Request HTTP section, was wondering if there are any example code written in iOS or Swift that I can follow along, that will be immensely helpful. Thank you for your time. I shall await your reply.
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
To start off something that I want to ensure is clear: -> From the code in your last post this looks as if you are trying to follow what we refer to as the "Companion App" flow for authentication. (Eric's post above where he starts with "There are 2 approaches to adding Alexa to your product." summarizes this flow and explains the options for interacting with AVS). By following this route you are trying use AVS not on your iOS device but rather to enable a separate physical device to interact with AVS. -> On the other hand: if you wish to authenticate an iOS app to directly interact with AVS you should see my post on this thread that I added Sep 9, 2015 4:20 PM. We're more than happy to help out with either of these routes I just want to verify that we understand what you're trying to accomplish so we can provide targeted advice to help you get up and going using AVS. Regarding the Error:APIKey for the Application is invalid - this could be two possible causes: 1) Please verify that the bundle id that you have entered on developer.amazon.com for the security profile you are using matches the bundle id of your application. If you are building on top of the iOS sample that we publish then the bundle id is com.amazon.AlexaCompanionAppSample. Otherwise you'll have to check the info tab of your xcode project for your bundle id 2) Ensure that you have completely deleted what is in the API key field before pasting in the bundle id. Basically verify that you paste in precisely the API key and don't have any extra spaces or characters around it. Regarding you're question for making calls to AVS you'll want to take a look at our API overview: https://developer.amazon.com/public/solutions/alexa/alexa-voice-service/rest-overview for making requests. I'd recommend you start by implementing the SpeechRecognizerRequest and handling a Speak directive. As Eric mentioned in his above post you will have to add the access token with every request. Message was edited by: elstryan@Amazon
10 |5000

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

Prasenjit avatar image
Prasenjit answered
Hello Ryan & Eric, I read your concerns on the ambiguity and let me take this moment to clarify with the following list 1. Yes I'm building an iOS application which will call AVS and fetch me responses to my requests without any pr 2. I'm also reading ASK along with AVS as I want to build some custom requests. So would I be able to use ASK with AVS without AMZN skill certification ? Now, as per the iOS app progress 1. I've been successful in getting back the authorization code as per point 6 => https://developer.amazon.com/public/solutions/alexa/alexa-voice-service/docs/authorizing-your-alexa-enabled-product-from-an-android-or-ios-mobile-app 2. I'm getting an Error in my console: LaunchServices: [b]ERROR: There is no registered handler for URL scheme com.amazon.lwa.sso[/b] The URL types, URL schemes, URL identifier are set in info.plist & also the code in Appdelegate in the method: This error does not crash or acts awkward as of now as I'm able to open the LWA page and get the authorization code, but I'd appreciate if you would please let me know what am I to do to get rid of this error message? - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { // Pass on the url to the SDK to parse authorization code from the url. BOOL isValidRedirectSignInURL = [AIMobileLib handleOpenURL:url sourceApplication:sourceApplication]; if(!isValidRedirectSignInURL) return NO; // App may also want to handle url return YES; } 3. I'm stuck at point 7 where I'm trying to fetch the access token -> https://developer.amazon.com/public/solutions/alexa/alexa-voice-service/docs/authorizing-your-alexa-enabled-product-from-an-android-or-ios-mobile-app I also have read the other link that you had posted in regards to check for ATS for iOS, which I had setup first thing when I used LWA, so simply put the app's info.plist does have the necessary key pairs as suggested. I'd like to share my code for fetching the access token and perhaps you can help me figure out my shortcomings as I'm facing an error [b]Code[/b] NSURLSessionConfiguration* defaultSessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration]; NSURLSession* defaultSession = [NSURLSession sessionWithConfiguration:defaultSessionConfiguration delegate:nil delegateQueue:[NSOperationQueue mainQueue]]; NSURL* url = [NSURL URLWithString:@" https://api.amazon.com/auth/O2/token"]; NSMutableURLRequest* urlRequest = [NSMutableURLRequest requestWithURL:url]; [urlRequest setHTTPMethod:@"POST"]; [urlRequest setValue:@"application/x-www-form-urlencoded;charset=UTF-8" forHTTPHeaderField:@"Content-Type"]; //NOTE: grant, token, and ,[ApplicationManager sharedManager].codeVerifier] are NSString variable which consists of the respective data NSString* requestBody = [NSString stringWithFormat:@"grant_type=%@&code=%@&redirect_uri=%@&client_id=%@&code_verifier=%@", grant,token,[AIMobileLib getRedirectUri],[AIMobileLib getClientId],[ApplicationManager sharedManager].codeVerifier]; // NSLog(@"\nJSON:%@", requestBody); [urlRequest setHTTPBody:[requestBody dataUsingEncoding:NSUTF8StringEncoding]]; NSURLSessionDataTask * dataTask =[defaultSession dataTaskWithRequest:urlRequest completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { NSLog(@"Response:%@ %@\n", response, error); if(error == nil) { NSString * text = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding]; NSLog(@"Data = %@",text); } else{ //PG: Get the result NSLog(@"dataAsString %@", [NSString stringWithUTF8String:[data bytes]]); NSError *error1; NSMutableDictionary * innerJson = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error1]; NSLog(@"\nResponse Dictionary:%@", innerJson); } }]; [dataTask resume]; But as soon I execute this piece of code my application crashes with the following error in the console: 2015-12-19 01:16:58.926 alexaTestApp[3360:264903] CFNetwork SSLHandshake failed (-9801) 2015-12-19 01:16:58.927 alexaTestApp[3360:264903] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9801) 2015-12-19 01:16:58.930 alexaTestApp[3360:264481] Response:(null) Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the server cannot be made." UserInfo={_kCFStreamErrorCodeKey=-9801, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, NSUnderlyingError=0x7fb968e3c400 {Error Domain=kCFErrorDomainCFNetwork Code=-1200 "(null)" UserInfo={_kCFStreamPropertySSLClientCertificateState=0, _kCFNetworkCFStreamSSLErrorOriginalValue=-9801, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9801}}, NSLocalizedDescription=An SSL error has occurred and a secure connection to the server cannot be made., NSErrorFailingURLKey= https://api.amazon.com/auth/O2/token, NSErrorFailingURLStringKey= https://api.amazon.com/auth/O2/token, _kCFStreamErrorDomainKey=3} 2015-12-19 01:16:58.939 alexaTestApp[3360:264481] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[NSString stringWithUTF8String:]: NULL cString' *** First throw call stack: ( 0 CoreFoundation 0x000000010c775f45 __exceptionPreprocess + 165 1 libobjc.A.dylib 0x000000010c1efdeb objc_exception_throw + 48 2 CoreFoundation 0x000000010c775e7d +[NSException raise:format:] + 205 3 Foundation 0x000000010a4bc1aa +[NSString stringWithUTF8String:] + 78 4 alexaTestApp 0x000000010a3e20be __55-[LoginWithAmazonViewController sendHTTPPostWithToken:]_block_invoke + 302 5 CFNetwork 0x000000010d0f8b3d __75-[__NSURLSessionLocal taskForClass:request:uploadFile:bodyData:completion:]_block_invoke + 19 6 CFNetwork 0x000000010d10afb6 __49-[__NSCFLocalSessionTask _task_onqueue_didFinish]_block_invoke + 302 7 Foundation 0x000000010a59b3b8 __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 7 8 Foundation 0x000000010a4d70e5 -[NSBlockOperation main] + 101 9 Foundation 0x000000010a4ba036 -[__NSOperationInternal _start:] + 646 10 Foundation 0x000000010a4b9c47 __NSOQSchedule_f + 194 11 libdispatch.dylib 0x000000010d87b49b _dispatch_client_callout + 8 12 libdispatch.dylib 0x000000010d8632af _dispatch_main_queue_callback_4CF + 1738 13 CoreFoundation 0x000000010c6d62e9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9 14 CoreFoundation 0x000000010c6978a9 __CFRunLoopRun + 2073 15 CoreFoundation 0x000000010c696e08 CFRunLoopRunSpecific + 488 16 GraphicsServices 0x000000010e924ad2 GSEventRunModal + 161 17 UIKit 0x000000010a94730d UIApplicationMain + 171 18 alexaTestApp 0x000000010a3e33df main + 111 19 libdyld.dylib 0x000000010d8af92d start + 1 20 ??? 0x0000000000000001 0x0 + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException As always I really appreciate the amount of time you all are spending in helping me learn, and thank you for understanding. I shall await your reply
10 |5000

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

Prasenjit avatar image
Prasenjit answered
FYI: [b]ATS[/b] NSExceptionDomains api.amazon.com NSExceptionRequiresForwardSecrecy and [b]URL types[/b] CFBundleURLSchemes amzn-com.someDomainCantDiscloseOnForum.alexaTestApp CFBundleURLName com.someDomainCantDiscloseOnForum.alexaTestApp
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
Hello Prasenjit, Thank you for your reply. First for your ATS add the following key value underneath NSExceptionRequiresForwardSecrecy: NSIncludesSubdomains NSExceptionAllowsInsecureHTTPLoads The reason these steps are not discussed on the LWA documentation is because it is unusual to try and call these APIs from a mobile device. I'll explain below. It appears as though you are trying to exchange an authorization code for an access token on your iPhone. This is the least direct and most complex way to accomplish getting an access token on your iPhone. The LWA SDK supports getting the access token on your iPhone directly without going through the work of getting an authorization code. Please see the following post: http://forums.developer.amazon.com/forums/thread.jspa?messageID=25327拯. If you modify the doLogin as outlined in that post you can authorize for access to alexa. Next: Once that gets a requestDidSucceed you need to fetch the access token: You can use: [AIMobileLib getAccessTokenForScopes:[NSArray arrayWithObjects:@"alexa:all", nil] withOverrideParams:nil delegate:tokenDelegate]; Then in your tokenDelegate (which will implement an AMZNGetAccessTokenDelegate) on your requestDidSucceeed all you need to do is call apiResult.result and that should contain your access token which you can pass in the header when you make requests to AVS Finally there is more details information here if you want additional background on all of these LWA calls, but hopefully this info is enough to get you an access token: https://developer.amazon.com/public/apis/engage/login-with-amazon/docs/use_sdk_ios.html
10 |5000

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

Prasenjit avatar image
Prasenjit answered
Hello Ryan & Eric, First of all, let me start by saying thank you for providing such great help; and, I would also like to start by saying that I have made some progress but as again am stuck now. 1. Progress being -> Got the Access Token as you suggested but also had to add this in the ATS => NSExceptionMinimumTLSVersion for TLSv1.0 [b]Question=> How do I got about refreshing the access token now, as I'm no longer following the steps listed in the documents ? [/b] 2. I'm trying to send across the Recognize Speech, but before I do, I have one more question: [b]Question=>What is the difference between SpeechRecognizer requests & Recognize Speech Requests ? [/b] 3. I'm stuck again :( with this error=> I'm following SpeechRecognizer steps [b]ERROR: Response code: 400 2015-12-21 22:13:02.179 alexaTestApp[9929:914091] Response string: {"error":{"code":"com.amazon.alexahttpproxy.exceptions.BadRequestException","message":"Unrecognized token 'Content': was expecting ('true', 'false' or 'null')\n at [Source: [LineReaderInputStreamAdaptor: [pos: 518][limit: 518][]]; line: 1, column: 9]"}}[/b] I've gone over my multipart form data segments but I'm at a loss to figure out the mistake, mind helping me out here? Here is my code: -(NSString*)createMetaData{ NSMutableDictionary* rootElement = [[NSMutableDictionary alloc] init]; //PG: Message Header section NSDictionary* deviceContextPayload = [NSDictionary dictionaryWithObjectsAndKeys:@"",@"streamId", @"0", @"offsetInMilliseconds", @"IDLE", @"playerActivity",nil]; // NSLog(@"\nPayload:%@", deviceContextPayload); NSDictionary* deviceContext = [NSDictionary dictionaryWithObjectsAndKeys:@"playbackState",@"name",@"AudioPlayer",@"namespace",deviceContextPayload,@"payload", nil]; // NSLog(@"\nDeviceContext: %@", deviceContext); [rootElement setObject:[NSDictionary dictionaryWithObject:[NSArray arrayWithObject:deviceContext] forKey:@"deviceContext"] forKey:@"messageHeader" ]; // NSLog(@"\nMessageHeader: %@", rootElement); //PG: Message body section NSDictionary* messageBodyParameters = [NSDictionary dictionaryWithObjectsAndKeys:@"audio/L16; rate=16000; channels=1", @"format", @"en-us", @"locale", @"alexa-close-talk", @"profile", nil]; // NSLog(@"\nMessageBody:%@", messageBodyParameters); [rootElement setObject:messageBodyParameters forKey:@"messageBody"]; // NSLog(@"\nRoot element: %@", rootElement); NSError* error; NSData* jsonData = [NSJSONSerialization dataWithJSONObject:rootElement options:NSJSONWritingPrettyPrinted error:&error]; NSString* jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; NSLog(@"\nJSON String: %@", jsonString); return jsonString; } -(void)postRecording{ //PG:AVS => https://developer.amazon.com/public/solutions/alexa/alexa-voice-service/rest/speechrecognizer-requests#message-body-json-object NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:self.urlString]]; request.cachePolicy = NSURLRequestReloadIgnoringLocalCacheData; request.HTTPShouldHandleCookies = false; request.timeoutInterval = 60; request.HTTPMethod = @"POST"; NSLog(@"\nAccessToken:%@", self.accessToken); [request addValue:[NSString stringWithFormat:@"Bearer %@",self.accessToken] forHTTPHeaderField:@"Authorization"]; NSString* boundry = [[NSUUID UUID] UUIDString]; NSString* contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundry]; [request addValue:contentType forHTTPHeaderField:@"Content-Type"]; [request addValue:@" access-alexa-na.amazon.com" forHTTPHeaderField:@"Host"]; NSMutableData* httpBody = [NSMutableData data]; //PG: JSON multipart header [httpBody appendData:[[NSString stringWithFormat:@"--%@\r\n", boundry] dataUsingEncoding:NSUTF8StringEncoding]]; // Content-Disposition: form-data; name="request" [httpBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"request\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; // Content-Type: application/json; charset=UTF-8 [httpBody appendData:[[NSString stringWithFormat:@"Content-Type: application/json; charset=UTF-8\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; //PG: JSON multipart body [httpBody appendData:[[self createMetaData] dataUsingEncoding:NSUTF8StringEncoding]]; [httpBody appendData:[[NSString stringWithFormat:@"\r\n"]dataUsingEncoding:NSUTF8StringEncoding]]; //PG: JSON Audio multipart header [httpBody appendData:[[NSString stringWithFormat:@"--%@\r\n",boundry] dataUsingEncoding:NSUTF8StringEncoding]]; // Content-Disposition: form-data; name="audio" [httpBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"audio\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; // Content-Type: audio/L16; rate=16000; channels=1 [httpBody appendData:[[NSString stringWithFormat:@"Content-Type: audio/L16; rate=16000; channels=1\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; //PG: Audio multipart body //TODO: Make audio a method param [httpBody appendData:self.audioData]; [httpBody appendData:[[NSString stringWithFormat:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; //PG: Terminating boundary term [httpBody appendData:[[NSString stringWithFormat:@"--%@--", boundry] dataUsingEncoding:NSUTF8StringEncoding]]; //PG: POST request to AMZN URL //PG: AMZN REST API Response codes => https://developer.amazon.com/public/apis/experience/cloud-drive/content/restful-api-response-codes NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration]; NSURLSession *session = [NSURLSession sessionWithConfiguration:config]; NSURLSessionUploadTask *uploadTask = [session uploadTaskWithRequest:request fromData:httpBody completionHandler:^(NSData *data,NSURLResponse *response,NSError *error) { // Handle response here if (!error) { NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response; NSLog(@"\nResponse code: %ld", httpResponse.statusCode); NSString* responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; NSLog(@"\nResponse string: %@", responseString); if (httpResponse.statusCode >=200 && httpResponse.statusCode <=299) { NSLog(@"\nResponse"); } } else{ NSLog(@"\nUpload Error:%@", [error localizedDescription]); } }]; [uploadTask resume]; } This is my recording code for setting up the channel -(void)setup{ NSArray* dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString* docsDir = dirPaths[0]; self.soundFilePath = [docsDir stringByAppendingString:@"alexaRecordedSample.wav"]; self.soundFileURL = [NSURL fileURLWithPath:self.soundFilePath]; //PG: The audio should be encoded as LPCM16 (16-bit linear PCM) format NSDictionary *recordSettings=[NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:AVAudioQualityMin], AVEncoderAudioQualityKey, [NSNumber numberWithInt:25600], AVEncoderBitRateKey, [NSNumber numberWithInt:1], AVNumberOfChannelsKey, [NSNumber numberWithFloat:16000.0], AVSampleRateKey, [NSNumber numberWithInt:kAudioFormatLinearPCM],AVFormatIDKey, nil]; NSError* error; self.audioSession = [AVAudioSession sharedInstance]; [self.audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:nil]; self.audioRecorder = [[AVAudioRecorder alloc] initWithURL:self.soundFileURL settings:recordSettings error:&error]; if (error) { NSLog(@"\nERROR:%@", [error localizedDescription]); } else{ [self.audioRecorder prepareToRecord]; } } [b]NOTE[/b]: I've been at this since yesterday morning, but unfortunately I cannot see through it to find the error, I'll keep trying and any help is appreciated. Thank you for your time.
10 |5000

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