Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audio engine crash on iOS when installing tap #261

Open
appalexhu opened this issue Nov 15, 2024 · 0 comments
Open

Audio engine crash on iOS when installing tap #261

appalexhu opened this issue Nov 15, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@appalexhu
Copy link

Description

The app crashes when trying to set up the audio engine in AudioProcessor.setupEngine(), specifically when calling installTap on the input node. The crash occurs with the following error:

Fatal Exception: com.apple.coreaudio.avfaudio
Required condition is false: IsFormatSampleRateAndChannelCountValid(format)

This issue has 237 crash events affecting 215 users
Képernyőfotó 2024-11-15 - 12 29 07

Képernyőfotó 2024-11-15 - 12 32 32

Stack Trace

# Crashlytics - Stack trace
# Platform: apple

Fatal Exception: com.apple.coreaudio.avfaudio
0  CoreFoundation                 0x827cc __exceptionPreprocess
1  libobjc.A.dylib                0x172e4 objc_exception_throw
2  CoreFoundation                 0x17d748 -[NSException initWithCoder:]
3  AVFAudio                       0x63124 AUGraphNodeBaseV3::CreateRecordingTap(unsigned long, unsigned int, AVAudioFormat*, void (AVAudioPCMBuffer*, AVAudioTime*) block_pointer)
4  AVFAudio                       0x1119b4 AVAudioEngineImpl::InstallTapOnNode(AVAudioNode*, unsigned long, unsigned int, AVAudioFormat*, void (AVAudioPCMBuffer*, AVAudioTime*) block_pointer)
5  AVFAudio                       0xe7330 -[AVAudioNode installTapOnBus:bufferSize:format:block:]
6  Language Learning              0x4a9a8c specialized AudioProcessor.setupEngine(inputDeviceID:) + 830 (AudioProcessor.swift:830)
7  Language Learning              0x4a4e3c AudioProcessor.startRecordingLive(inputDeviceID:callback:) + 858 (AudioProcessor.swift:858)
8  Language Learning              0x17cb4 closure #1 in SubtitleView.startWhisperKitTranscription() + 583 (SubtitleView.swift:583)
9  Language Learning              0x2d8c9 partial apply for closure #1 in SubtitleView.loadModel(_:redownload:completion:)
10 Language Learning              0x10b715 specialized thunk for @escaping @isolated(any) @callee_guaranteed @async () -> (@out A)
11 Language Learning              0x2c19d partial apply for closure #1 in RemoteConfigViewModel.init() (<compiler-generated>)
12 libswift_Concurrency.dylib     0x69e39 completeTaskWithClosure(swift::AsyncContext*, swift::SwiftError*)

Crashed: com.google.firebase.crashlytics.ios.exception
0  Language Learning              0x7d9920 FIRCLSProcessRecordAllThreads + 392 (FIRCLSProcess.c:392)
1  Language Learning              0x7d9d04 FIRCLSProcessRecordAllThreads + 423 (FIRCLSProcess.c:423)
2  Language Learning              0x7e7f28 FIRCLSHandler + 34 (FIRCLSHandler.m:34)
3  Language Learning              0x7e7d38 __FIRCLSExceptionRecord_block_invoke + 240 (FIRCLSException.mm:240)
4  libdispatch.dylib              0x40d0 _dispatch_client_callout + 20
5  libdispatch.dylib              0x13750 _dispatch_lane_barrier_sync_invoke_and_complete + 56
6  Language Learning              0x7e6c94 FIRCLSExceptionRecord + 242 (FIRCLSException.mm:242)
7  Language Learning              0x7e77f0 FIRCLSExceptionRecordNSException + 126 (FIRCLSException.mm:126)
8  Language Learning              0x7e689c FIRCLSTerminateHandler() + 407 (FIRCLSException.mm:407)
9  libc++abi.dylib                0x1287c std::__terminate(void (*)()) + 16
10 libc++abi.dylib                0x160ac __cxa_increment_exception_refcount + 202
11 libobjc.A.dylib                0x2e650 objc_exception_rethrow + 44
12 CoreFoundation                 0x52934 CFRunLoopRunSpecific + 848
13 GraphicsServices               0x11c4 GSEventRunModal + 164
14 UIKitCore                      0x3d2eb0 -[UIApplication _run] + 816
15 UIKitCore                      0x4815b4 UIApplicationMain + 340
16 SwiftUI                        0x101f98 closure #1 in KitRendererCommon(_:) + 168
17 SwiftUI                        0xe2664 runApp<A>(_:) + 100
18 SwiftUI                        0xe5490 static App.main() + 180
19 Language Learning              0x37a00 main + 4373019136 (LanguageLearningApp.swift:4373019136)
20 ???                            0x1bd6d2ec8 (Missing)

com.apple.CoreMotion.MotionThread
0  libsystem_kernel.dylib         0x1688 mach_msg2_trap + 8
1  libsystem_kernel.dylib         0x4d98 mach_msg2_internal + 80
2  libsystem_kernel.dylib         0x4cb0 mach_msg_overwrite + 424
3  libsystem_kernel.dylib         0x4afc mach_msg + 24
4  CoreFoundation                 0x53a84 __CFRunLoopServiceMachPort + 160
5  CoreFoundation                 0x53130 __CFRunLoopRun + 1212
6  CoreFoundation                 0x52830 CFRunLoopRunSpecific + 588
7  CoreFoundation                 0xbdcec CFRunLoopRun + 64
8  CoreMotion                     0x10084 (Missing UUID ad76b51c2c19371888c6e6a9d73d5868)
9  libsystem_pthread.dylib        0x637c _pthread_start + 136
10 libsystem_pthread.dylib        0x1494 thread_start + 8

com.apple.uikit.eventfetch-thread
0  libsystem_kernel.dylib         0x1688 mach_msg2_trap + 8
1  libsystem_kernel.dylib         0x4d98 mach_msg2_internal + 80
2  libsystem_kernel.dylib         0x4cb0 mach_msg_overwrite + 424
3  libsystem_kernel.dylib         0x4afc mach_msg + 24
4  CoreFoundation                 0x53a84 __CFRunLoopServiceMachPort + 160
5  CoreFoundation                 0x53130 __CFRunLoopRun + 1212
6  CoreFoundation                 0x52830 CFRunLoopRunSpecific + 588
7  Foundation                     0xb7500 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 212
8  Foundation                     0xb7350 -[NSRunLoop(NSRunLoop) runUntilDate:] + 64
9  UIKitCore                      0x3e6358 -[UIEventFetcher threadMain] + 420
10 Foundation                     0xc86c8 __NSThread__start__ + 724
11 libsystem_pthread.dylib        0x637c _pthread_start + 136
12 libsystem_pthread.dylib        0x1494 thread_start + 8

Thread
0  libsystem_kernel.dylib         0x71b0 __semwait_signal + 8
1  libsystem_c.dylib              0x17a78 nanosleep + 220
2  libsystem_c.dylib              0x75550 sleep + 52
3  Shake                          0x109eb8 monitorCachedData + 748
4  libsystem_pthread.dylib        0x637c _pthread_start + 136
5  libsystem_pthread.dylib        0x1494 thread_start + 8

SHKCrash Exception Handler (Secondary)
0  libsystem_kernel.dylib         0x1688 mach_msg2_trap + 8
1  libsystem_kernel.dylib         0x4d98 mach_msg2_internal + 80
2  libsystem_kernel.dylib         0x2bfc thread_suspend + 108
3  Shake                          0x10a978 handleExceptions + 124
4  libsystem_pthread.dylib        0x637c _pthread_start + 136
5  libsystem_pthread.dylib        0x1494 thread_start + 8

SHKCrash Exception Handler (Primary)
0  libsystem_kernel.dylib         0x1688 mach_msg2_trap + 8
1  libsystem_kernel.dylib         0x4e30 mach_msg2_internal + 232
2  libsystem_kernel.dylib         0x4cb0 mach_msg_overwrite + 424
3  libsystem_kernel.dylib         0x4afc mach_msg + 24
4  Shake                          0x10a9a4 handleExceptions + 168
5  libsystem_pthread.dylib        0x637c _pthread_start + 136
6  libsystem_pthread.dylib        0x1494 thread_start + 8

com.google.firebase.crashlytics.MachExceptionServer
0  libsystem_kernel.dylib         0x1688 mach_msg2_trap + 8
1  libsystem_kernel.dylib         0x4d98 mach_msg2_internal + 80
2  libsystem_kernel.dylib         0x4cb0 mach_msg_overwrite + 424
3  libsystem_kernel.dylib         0x4afc mach_msg + 24
4  Language Learning              0x7e84ec FIRCLSMachExceptionServer + 196 (FIRCLSMachException.c:196)
5  libsystem_pthread.dylib        0x637c _pthread_start + 136
6  libsystem_pthread.dylib        0x1494 thread_start + 8

com.apple.NSURLConnectionLoader
0  libsystem_kernel.dylib         0x1688 mach_msg2_trap + 8
1  libsystem_kernel.dylib         0x4d98 mach_msg2_internal + 80
2  libsystem_kernel.dylib         0x4cb0 mach_msg_overwrite + 424
3  libsystem_kernel.dylib         0x4afc mach_msg + 24
4  CoreFoundation                 0x53a84 __CFRunLoopServiceMachPort + 160
5  CoreFoundation                 0x53130 __CFRunLoopRun + 1212
6  CoreFoundation                 0x52830 CFRunLoopRunSpecific + 588
7  CFNetwork                      0xfdee0 +[__CFN_CoreSchedulingSetRunnable _run:] + 416
8  Foundation                     0xc86c8 __NSThread__start__ + 724
9  libsystem_pthread.dylib        0x637c _pthread_start + 136
10 libsystem_pthread.dylib        0x1494 thread_start + 8

Thread
0  libsystem_pthread.dylib        0x1480 start_wqthread + 9127969918

console_log_reporter_write_log_queue
0  libsystem_kernel.dylib         0x90f8 fsync + 8
1  libsqlite3.dylib               0x4c014 sqlite3_free_table + 46604
2  libsqlite3.dylib               0x550e8 sqlite3_randomness + 1652
3  libsqlite3.dylib               0x4bbd4 sqlite3_free_table + 45516
4  libsqlite3.dylib               0x3c518 sqlite3_value_text + 19792
5  libsqlite3.dylib               0x3c0e0 sqlite3_value_text + 18712
6  libsqlite3.dylib               0x1580c sqlite3_finalize + 1800
7  libsqlite3.dylib               0x36548 sqlite3_step + 45504
8  libsqlite3.dylib               0x2b748 sqlite3_step + 960
9  Shake                          0x30aa8 -[SHKSqliteDatabase SQL_InsertUpdate:sortedKeys:paramDictonary:databaseKeys:] + 696
10 Shake                          0x31964 -[SHKSqliteDatabase insertDatabaseRecord:] + 260
11 Shake                          0x32368 -[SHKSqliteDatabase bulkInsertDatabaseRecords:] + 216
12 Shake                          0x317fc -[SHKSqliteDatabase bulkInsertBlackBoxRecords:] + 56
13 Shake                          0x1d310 __52-[SHKConsoleLogReporter bulkInsertConsoleLogs:sync:]_block_invoke + 468
14 libdispatch.dylib              0x2370 _dispatch_call_block_and_release + 32
15 libdispatch.dylib              0x40d0 _dispatch_client_callout + 20
16 libdispatch.dylib              0xb6d8 _dispatch_lane_serial_drain + 744
17 libdispatch.dylib              0xc1e0 _dispatch_lane_invoke + 380
18 libdispatch.dylib              0x17258 _dispatch_root_queue_drain_deferred_wlh + 288
19 libdispatch.dylib              0x16aa4 _dispatch_workloop_worker_thread + 540
20 libsystem_pthread.dylib        0x4c7c _pthread_wqthread + 288
21 libsystem_pthread.dylib        0x1488 start_wqthread + 8

Thread
0  libsystem_kernel.dylib         0x1410 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x4cc8 _pthread_wqthread + 364
2  libsystem_pthread.dylib        0x1488 start_wqthread + 8

JavaScriptCore libpas scavenger
0  libsystem_kernel.dylib         0x6f90 __psynch_cvwait + 8
1  libsystem_pthread.dylib        0x3a50 _pthread_cond_wait + 1204
2  JavaScriptCore                 0x15a6ca4 scavenger_thread_main + 1512
3  libsystem_pthread.dylib        0x637c _pthread_start + 136
4  libsystem_pthread.dylib        0x1494 thread_start + 8

Thread
0  libsystem_pthread.dylib        0x1480 start_wqthread + 9127969918

Thread
0  libsystem_pthread.dylib        0x1480 start_wqthread + 9127969918

Thread
0  libsystem_pthread.dylib        0x1480 start_wqthread + 9127969918

AudioSession - RootQueue
0  libsystem_kernel.dylib         0x161c semaphore_timedwait_trap + 8
1  libdispatch.dylib              0x46e8 _dispatch_sema4_timedwait + 64
2  libdispatch.dylib              0x4ce8 _dispatch_semaphore_wait_slow + 76
3  libdispatch.dylib              0x15b60 _dispatch_worker_thread + 324
4  libsystem_pthread.dylib        0x637c _pthread_start + 136
5  libsystem_pthread.dylib        0x1494 thread_start + 8

caulk.messenger.shared:high
0  libsystem_kernel.dylib         0x1604 semaphore_wait_trap + 8
1  caulk                          0x4a0c caulk::semaphore::timed_wait(double) + 220
2  caulk                          0x48c4 caulk::concurrent::details::worker_thread::run() + 36
3  caulk                          0x480c void* caulk::thread_proxy<std::__1::tuple<caulk::thread::attributes, void (caulk::concurrent::details::worker_thread::*)(), std::__1::tuple<caulk::concurrent::details::worker_thread*>>>(void*) + 96
4  libsystem_pthread.dylib        0x637c _pthread_start + 136
5  libsystem_pthread.dylib        0x1494 thread_start + 8

com.apple.audio.toolbox.AUScheduledParameterRefresher
0  libsystem_kernel.dylib         0x1604 semaphore_wait_trap + 8
1  caulk                          0x4a0c caulk::semaphore::timed_wait(double) + 220
2  caulk                          0x48c4 caulk::concurrent::details::worker_thread::run() + 36
3  caulk                          0x480c void* caulk::thread_proxy<std::__1::tuple<caulk::thread::attributes, void (caulk::concurrent::details::worker_thread::*)(), std::__1::tuple<caulk::concurrent::details::worker_thread*>>>(void*) + 96
4  libsystem_pthread.dylib        0x637c _pthread_start + 136
5  libsystem_pthread.dylib        0x1494 thread_start + 8

caulk::deferred_logger
0  libsystem_kernel.dylib         0x1604 semaphore_wait_trap + 8
1  caulk                          0x4a0c caulk::semaphore::timed_wait(double) + 220
2  caulk                          0x48c4 caulk::concurrent::details::worker_thread::run() + 36
3  caulk                          0x480c void* caulk::thread_proxy<std::__1::tuple<caulk::thread::attributes, void (caulk::concurrent::details::worker_thread::*)(), std::__1::tuple<caulk::concurrent::details::worker_thread*>>>(void*) + 96
4  libsystem_pthread.dylib        0x637c _pthread_start + 136
5  libsystem_pthread.dylib        0x1494 thread_start + 8

My code:

    private func startWhisperKitTranscription() {
        print("startWhisperKitTranscription")
        guard let whisperKit = whisperKit else { return }
        
        isTranscribing = true
        print("isTranscribing = true")
        Task {
            do {
              
                let audioProcessor = AudioProcessor()
                try audioProcessor.startRecordingLive { buffer in
                    print("audioProcessor.startRecordingLive")
                }
                
                while isTranscribing {
                    let samples = Array(audioProcessor.audioSamples)
                    let options = DecodingOptions(
                        task: .transcribe,
                        language: selectedLanguage,
                        temperature: 0.0,
                        sampleLength: 224
                    )
                    
                    let results = try await whisperKit.transcribe(audioArray: samples, decodeOptions: options)
                    
                    if let transcription = results.first {
                        await MainActor.run {
                            print(currentText)
                            ///etc...
                        }
                    }
                    
                    try await Task.sleep(nanoseconds: 1_000_000_000)
                }
                
                audioProcessor.stopRecording()
            } catch {
                print("Error during WhisperKit transcription: \(error)")
                isTranscribing = false
            }
        }
    }
@ZachNagengast ZachNagengast added the bug Something isn't working label Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants