wit-ai/wit-ios

Start function in Swift throwing error

tillson opened this issue · 1 comments

Calling Wit.sharedInstance().start() in Swift triggers the following error:

 *** Terminating app due to uncaught exception 'Invalid AVAudioSession state', reason: 'You should call setCategory and setActive, please see the documentation.'

I installed using CocoaPods... Not really sure what the problem is.

Look at step 5 of the quick start, the section for setting up the AppDelegate.m
https://wit.ai/docs/ios/4.0.0/quickstart

#import "AppDelegate.h"
#import <AVFoundation/AVFoundation.h>
#import <Wit/Wit.h>

@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
    [[AVAudioSession sharedInstance] setActive:YES error:nil];

    [Wit sharedInstance].accessToken = @"YOUR_ACCESS_TOKEN"; // replace xxx by your Wit.AI access token
    //enabling detectSpeechStop will automatically stop listening the microphone when the user stop talking
    [Wit sharedInstance].detectSpeechStop = WITVadConfigDetectSpeechStop;

    return YES;
}