wit-ai / wit-ios

Wit.ai iOS client
Other
222 stars 71 forks source link

Start function in Swift throwing error #60

Closed tillson closed 8 years ago

tillson commented 8 years ago

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.

tielur commented 8 years ago

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;
}