argmaxinc / WhisperKit

On-device Speech Recognition for Apple Silicon
http://argmaxinc.com/blog/whisperkit
MIT License
3.92k stars 331 forks source link

Crash when starting whisperKit in iOS simulator or visionPro simulator #65

Closed ArchieGoodwin closed 8 months ago

ArchieGoodwin commented 8 months ago

I am getting this error when trying to start WhisperKit in any simulator. Can someone say what could it be and how to fix?

Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: IsFormatSampleRateAndChannelCountValid(format)' First throw call stack: ( 0 CoreFoundation 0x00000001804bceec __exceptionPreprocess + 172 1 libobjc.A.dylib 0x0000000180087068 objc_exception_throw + 56 2 CoreFoundation 0x00000001804bcd90 +[NSException raise:format:] + 0 3 AVFAudio 0x00000001c7789130 _Z19AVAE_RaiseExceptionP8NSStringz + 48 4 AVFAudio 0x00000001c77e0b84 _ZN17AUGraphNodeBaseV318CreateRecordingTapEmjP13AVAudioFormatU13block_pointerFvP16AVAudioPCMBufferP11AVAudioTimeE + 712 5 AVFAudio 0x00000001c78504d4 -[AVAudioNode installTapOnBus:bufferSize:format:block:] + 1324 6 languagelearn 0x0000000102091988 $s10WhisperKit14AudioProcessorC11setupEngine13inputDeviceIDSo07AVAudioF0CSSSg_tKF + 852 7 languagelearn 0x0000000102090c4c $s10WhisperKit14AudioProcessorC18startRecordingLive13inputDeviceID8callbackySSSg_ySaySfGcSgtKF + 224 8 languagelearn 0x0000000102090b2c $s10WhisperKit14AudioProcessorCAA0C10ProcessingA2aDP18startRecordingLive13inputDeviceID8callbackySSSg_ySaySfGcSgtKFTW + 24 9 languagelearn 0x000000010206bc04 $s13languagelearn11ContentViewV14startRecordingyySbFyyYaYbcfUTY1 + 372 10 languagelearn 0x0000000102077ea5 $s13languagelearn11ContentViewV14startRecordingyySbFyyYaYbcfUTATQ0 + 1 11 languagelearn 0x0000000102085369 $sxIeghHr_xs5Error_pIegHrzo_s8SendableRzs5NeverORs_r0lTRTQ0 + 1 12 languagelearn 0x00000001020873cd $sxIeghHr_xs5Error_pIegHrzo_s8SendableRzs5NeverORs_r0lTRTATQ0 + 1 13 libswift_Concurrency.dylib 0x000000020bfbf621 _ZL23completeTaskWithClosurePN5swift12AsyncContextEPNS_10SwiftErrorE + 1 ) libc++abi: terminating due to uncaught exception of type NSException

ZachNagengast commented 8 months ago

@ArchieGoodwin could you also share your hardware and OS version?

ArchieGoodwin commented 8 months ago

MacBook Pro M1 Max, 14.2.1 (23C71), Xcode 15.3, VisionPro simulator 1.1

ZachNagengast commented 8 months ago

@ArchieGoodwin after looking into this, I was able to resolve the issue by running the following code before starting any recording:

        let audioSession = AVAudioSession.sharedInstance()
        do {
            try audioSession.setCategory(.playAndRecord, options: .defaultToSpeaker)
            try audioSession.setActive(true, options: .notifyOthersOnDeactivation)
        } catch let error as NSError {
            print("AVAudioSession error:", error)
        }

You can run it in your app's code for now, and we'll add it to the standard flow soon. Let me know if this works for you or it still has issues.

ArchieGoodwin commented 8 months ago

It's working! Thank you very much!

ZachNagengast commented 8 months ago

@ArchieGoodwin after looking into this, I was able to resolve the issue by running the following code before starting any recording:

        let audioSession = AVAudioSession.sharedInstance()
        do {
            try audioSession.setCategory(.playAndRecord, options: .defaultToSpeaker)
            try audioSession.setActive(true, options: .notifyOthersOnDeactivation)
        } catch let error as NSError {
            print("AVAudioSession error:", error)
        }

You can run it in your app's code for now, and we'll add it to the standard flow soon. Let me know if this works for you or it still has issues.

This fix is now built into startRecordingLive with #52