argmaxinc / WhisperKit

On-device Speech Recognition for Apple Silicon

Home Page:https://takeargmax.com/blog/whisperkit

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Crash when starting whisperKit in iOS simulator or visionPro simulator

ArchieGoodwin opened this issue · comments

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 $s13languagelearn11ContentViewV14startRecordingyySbFyyYaYbcfU_TY1
+ 372
10 languagelearn 0x0000000102077ea5 $s13languagelearn11ContentViewV14startRecordingyySbFyyYaYbcfU_TATQ0
+ 1
11 languagelearn 0x0000000102085369 $sxIeghHr_xs5Error_pIegHrzo_s8SendableRzs5NeverORs_r0_lTRTQ0
+ 1
12 languagelearn 0x00000001020873cd $sxIeghHr_xs5Error_pIegHrzo_s8SendableRzs5NeverORs_r0_lTRTATQ0
+ 1
13 libswift_Concurrency.dylib 0x000000020bfbf621 _ZL23completeTaskWithClosurePN5swift12AsyncContextEPNS_10SwiftErrorE + 1
)
libc++abi: terminating due to uncaught exception of type NSException

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

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

@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.

It's working! Thank you very much!

@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