Jeffrey Berthiaume
Jeffrey Berthiaume

Reputation: 4594

How to get SpeechKit and AVCaptureDevice to work with each other

I am using SpeechKit from Nuance to transcribe text from video as I record it. However, when SpeechKit is active, AVAudioSession generates the following error:

AVAudioSession.mm:646: -[AVAudioSession setActive:withOptions:error:]: Deactivating an audio session that has running I/O. All I/O should be stopped or paused prior to deactivating the audio session.

Disabling SpeechKit lets me record and preview the video. Enabling it generates the transcribed text, but doesn't record the video.

I have put a sample project online at:

https://github.com/jeffreality/iOSVideoTranscriber

My goal is to save the video with audio, as well as have a transcription.

Upvotes: 3

Views: 541

Answers (1)

gabbler
gabbler

Reputation: 13766

You can move the following line to viewDidLoad:

#if ENABLE_TRANSCRIPTION

[SpeechKit setupWithID:@"Your ID"
                  host:@"dfo.nmdp.nuancemobility.net"
                  port:443
                useSSL:NO
              delegate:nil];
#endif

This ensures that speechKit has already been set up when you create your own capture session in viewDidAppear.

SpeechKit delegate method recognizerDidFinishRecording is called when the recognizer stops recording audio. It is automatically called when a silence is detected, or manually called when you do [voiceSearch stopRecording]. When this happens, your own recording has not finished, it needs time to save the audio file to disk, and the error message says all i/o should stop prior to deactivating an audio session. You can see a log by the sdk release audio session 1, which I think is deactivating a session and release it. So I think you should add this in the above method.

[[self.session.outputs[1] connectionWithMediaType:AVMediaTypeAudio] setEnabled:NO];

The output is AVCaptureMovieFileOutput you set up earlier, and connection is an audio connection, doing this seems to make the error disappear.

Upvotes: 2

Related Questions