AVFAudio:AVAE_RaiseException(NSString*, ...) + 52

AVFAudio: AVAE_RaiseException(NSString*, ...) + 52

提问人:Florentin Lupascu 提问时间:8/17/2023 更新时间:8/17/2023 访问量:66

问:

当我单击按钮时,我想使用 Apple 的功能将对话附加到一个。 问题是我的应用程序有时会崩溃,我不知道我的代码中可能有什么问题。 我将在下面附上我的代码以及我的崩溃的回溯。 任何帮助将不胜感激!Start RecordingtextViewSpeechRecognizer

我的代码:

func startRecording() {
        
        startStopRecordBtn.setImage(UIImage(#imageLiteral(resourceName: "microphone_off")), for: .normal)
        if UserDefaults.standard.bool(forKey: Constants.darkTheme) {
            commentTextView.textColor = .white
        } else {
            commentTextView.textColor = .black
        }
        commentTextView.isUserInteractionEnabled = false
        recordingLabel.text = Constants.recording
        
        if recognitionTask != nil {
            recognitionTask?.cancel()
            recognitionTask = nil
        }
        
        let audioSession = AVAudioSession.sharedInstance()
        do {
            try audioSession.setCategory(AVAudioSession.Category.record)
            try audioSession.setMode(AVAudioSession.Mode.measurement)
            try audioSession.setActive(true, options: .notifyOthersOnDeactivation)
        } catch {
            showAlertWithTitle(message: Constants.error)
        }
        
        recognitionRequest = SFSpeechAudioBufferRecognitionRequest()
        
        let inputNode = audioEngine.inputNode
        
        guard let recognitionRequest = recognitionRequest else {
            fatalError(Constants.error)
        }
        
        recognitionRequest.shouldReportPartialResults = true
        
        recognitionTask = speechRecognizer?.recognitionTask(with: recognitionRequest, resultHandler: { (result, error) in
            
            var isFinal = false
            
            if result != nil {
                
                self.commentTextView.text = result?.bestTranscription.formattedString
                isFinal = (result?.isFinal)!
            }
            
            if error != nil || isFinal {
                self.audioEngine.stop()
                inputNode.removeTap(onBus: 0)
                
                self.recognitionRequest = nil
                self.recognitionTask = nil
                
                self.startStopRecordBtn.isEnabled = true
            }
        })
        
        let recordingFormat = inputNode.outputFormat(forBus: 0)
        inputNode.installTap(onBus: 0, bufferSize: 1024, format: recordingFormat) { (buffer, when) in
            self.recognitionRequest?.append(buffer)
        }
        
        audioEngine.prepare()
        
        do {
            try audioEngine.start()
        } catch {
            showAlertWithTitle(message: Constants.error)
        }
    }

带有崩溃位置的屏幕截图:

enter image description here

崩溃的回溯:

Date/Time:           2023-08-03 08:32:28.9571 +0100
Launch Time:         2023-08-03 08:04:02.0301 +0100
OS Version:          iPhone OS 16.0 (20A362)
Release Type:        User
Baseband Version:    2.09.01
Report Version:      104

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Triggered by Thread:  0

Last Exception Backtrace:
0   CoreFoundation                  0x1aa78a248 __exceptionPreprocess + 164 (NSException.m:202)
1   libobjc.A.dylib                 0x1a3b4fa68 objc_exception_throw + 60 (objc-exception.mm:356)
2   CoreFoundation                  0x1aa8f63b8 +[NSException raise:format:arguments:] + 96 (NSException.m:0)
3   AVFAudio                        0x1c0e42624 AVAE_RaiseException(NSString*, ...) + 52 (AVAEInternal.h:69)
4   AVFAudio                        0x1c0ea5130 AUGraphNodeBaseV3::CreateRecordingTap(unsigned long, unsigned int, AVAudioFormat*, void (AVAudioPCMBuffer*, AVAudioTime*) block_pointer) + 760 (AVAEInternal.h:77)
5   AVFAudio                        0x1c0f0ea9c -[AVAudioNode installTapOnBus:bufferSize:format:block:] + 1412 (AVAudioEngineGraph.mm:2029)
6   MyFirstApp                      0x102949064 InspectionCommentsVC.startRecording() + 1632 (InspectionCommentsVC.swift:278)
7   MyFirstApp                      0x10294a450 specialized InspectionCommentsVC.startStopMicrophoneBtn(_:) + 256 (InspectionCommentsVC.swift:198)
8   MyFirstApp                      0x102948654 InspectionCommentsVC.startStopMicrophoneBtn(_:) + 4 (<compiler-generated>:0)
9   MyFirstApp                      0x102948654 @objc InspectionCommentsVC.startStopMicrophoneBtn(_:) + 48
10  UIKitCore                       0x1acb5d6d8 -[UIApplication sendAction:to:from:forEvent:] + 100 (UIPerformVoidSelector.h:56)
11  UIKitCore                       0x1acb5d3d8 -[UIControl sendAction:to:forEvent:] + 112 (UIControl.m:872)
12  UIKitCore                       0x1acb5cd6c -[UIControl _sendActionsForEvents:withEvent:] + 324 (UIControl.m:943)
13  UIKitCore                       0x1acb5cc10 -[UIButton _sendActionsForEvents:withEvent:] + 124 (UIButton.m:4201)
14  UIKitCore                       0x1acb5c848 -[UIControl touchesEnded:withEvent:] + 396 (UIControl.m:638)
15  UIKitCore                       0x1aca0b268 -[UIWindow _sendTouchesForEvent:] + 776 (UIWindow.m:3180)
16  UIKitCore                       0x1aca0a684 -[UIWindow sendEvent:] + 3284 (UIWindow.m:3480)
17  UIKitCore                       0x1aca09944 -[UIApplication sendEvent:] + 672 (UIApplication.m:12503)
18  UIKitCore                       0x1aca09000 __dispatchPreprocessedEventFromEventQueue + 7088 (UIEventDispatcher.m:2371)
19  UIKitCore                       0x1aca50d64 __processEventQueue + 5632 (UIEventDispatcher.m:2680)
20  UIKitCore                       0x1ad697a30 updateCycleEntry + 168 (UIEventDispatcher.m:116)
21  UIKitCore                       0x1acf5f678 _UIUpdateSequenceRun + 84 (_UIUpdateSequence.mm:112)
22  UIKitCore                       0x1ad59e904 schedulerStepScheduledMainSection + 172 (_UIUpdateScheduler.m:987)
23  UIKitCore                       0x1ad59dad0 runloopSourceCallback + 92 (_UIUpdateScheduler.m:1079)
24  CoreFoundation                  0x1aa85622c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28 (CFRunLoop.c:1974)
25  CoreFoundation                  0x1aa862614 __CFRunLoopDoSource0 + 176 (CFRunLoop.c:2018)
26  CoreFoundation                  0x1aa7e651c __CFRunLoopDoSources0 + 244 (CFRunLoop.c:2055)
27  CoreFoundation                  0x1aa7fbeb8 __CFRunLoopRun + 836 (CFRunLoop.c:2970)
28  CoreFoundation                  0x1aa8011e4 CFRunLoopRunSpecific + 612 (CFRunLoop.c:3390)
29  GraphicsServices                0x1e3621368 GSEventRunModal + 164 (GSEvent.c:2196)
30  UIKitCore                       0x1accb0d88 -[UIApplication _run] + 888 (UIApplication.m:3726)
31  UIKitCore                       0x1accb09ec UIApplicationMain + 340 (UIApplication.m:5316)
32  MyFirstApp                      0x1028daf24 main + 68 (AppDelegate.swift:14)
33  dyld                            0x1c8b25948 start + 2504 (dyldMain.cpp:1168)

Thread 0 name:
Thread 0 Crashed:
0   libsystem_kernel.dylib          0x00000001e6e72200 __pthread_kill + 8 (:-1)
1   libsystem_pthread.dylib         0x00000001f70af1ac pthread_kill + 268 (pthread.c:1670)
2   libsystem_c.dylib               0x00000001b1c69ca0 abort + 180 (abort.c:118)
3   libc++abi.dylib                 0x00000001f6ff1b8c abort_message + 132 (abort_message.cpp:78)
4   libc++abi.dylib                 0x00000001f6fe1a80 demangling_terminate_handler() + 336 (cxa_default_handlers.cpp:71)
5   libobjc.A.dylib                 0x00000001a3b55eec _objc_terminate() + 144 (objc-exception.mm:498)
6   libc++abi.dylib                 0x00000001f6ff0f28 std::__terminate(void (*)()) + 20 (cxa_handlers.cpp:59)
7   libc++abi.dylib                 0x00000001f6ff3ecc __cxa_rethrow + 148 (cxa_exception.cpp:616)
8   libobjc.A.dylib                 0x00000001a3b51854 objc_exception_rethrow + 44 (objc-exception.mm:401)
9   CoreFoundation                  0x00000001aa8012a8 CFRunLoopRunSpecific + 808 (CFRunLoop.c:3406)
10  GraphicsServices                0x00000001e3621368 GSEventRunModal + 164 (GSEvent.c:2196)
11  UIKitCore                       0x00000001accb0d88 -[UIApplication _run] + 888 (UIApplication.m:3726)
12  UIKitCore                       0x00000001accb09ec UIApplicationMain + 340 (UIApplication.m:5316)
13  MyFirstApp                      0x00000001028daf24 main + 68 (AppDelegate.swift:14)
14  dyld                            0x00000001c8b25948 start + 2504 (dyldMain.cpp:1168)

Thread 1 name:
Thread 1:
0   libsystem_kernel.dylib          0x00000001e6e6bb48 mach_msg2_trap + 8 (:-1)
1   libsystem_kernel.dylib          0x00000001e6e7e008 mach_msg2_internal + 80 (mach_msg.c:201)
2   libsystem_kernel.dylib          0x00000001e6e7e248 mach_msg_overwrite + 388 (mach_msg.c:0)
3   libsystem_kernel.dylib          0x00000001e6e6c08c mach_msg + 24 (mach_msg.c:323)
4   CoreFoundation                  0x00000001aa7fae00 __CFRunLoopServiceMachPort + 160 (CFRunLoop.c:2639)
5   CoreFoundation                  0x00000001aa7fc044 __CFRunLoopRun + 1232 (CFRunLoop.c:3022)
6   CoreFoundation                  0x00000001aa8011e4 CFRunLoopRunSpecific + 612 (CFRunLoop.c:3390)
7   Foundation                      0x00000001a4c09818 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 212 (NSRunLoop.m:373)
8   Foundation                      0x00000001a4c09700 -[NSRunLoop(NSRunLoop) runUntilDate:] + 64 (NSRunLoop.m:420)
9   UIKitCore                       0x00000001acde588c -[UIEventFetcher threadMain] + 436 (UIEventFetcher.m:1212)
10  Foundation                      0x00000001a4c22ce8 __NSThread__start__ + 716 (NSThread.m:968)
11  libsystem_pthread.dylib         0x00000001f70a96cc _pthread_start + 148 (pthread.c:893)
12  libsystem_pthread.dylib         0x00000001f70a8ba4 thread_start + 8 (:-1)

Thread 2 name:
Thread 2:
0   libsystem_kernel.dylib          0x00000001e6e6bb48 mach_msg2_trap + 8 (:-1)
1   libsystem_kernel.dylib          0x00000001e6e7e008 mach_msg2_internal + 80 (mach_msg.c:201)
2   libsystem_kernel.dylib          0x00000001e6e7e248 mach_msg_overwrite + 388 (mach_msg.c:0)
3   libsystem_kernel.dylib          0x00000001e6e6c08c mach_msg + 24 (mach_msg.c:323)
4   CoreFoundation                  0x00000001aa7fae00 __CFRunLoopServiceMachPort + 160 (CFRunLoop.c:2639)
5   CoreFoundation                  0x00000001aa7fc044 __CFRunLoopRun + 1232 (CFRunLoop.c:3022)
6   CoreFoundation                  0x00000001aa8011e4 CFRunLoopRunSpecific + 612 (CFRunLoop.c:3390)
7   CFNetwork                       0x00000001abb4fbac +[__CFN_CoreSchedulingSetRunnable _run:] + 392 (CoreSchedulingSet.mm:1372)
8   Foundation                      0x00000001a4c22ce8 __NSThread__start__ + 716 (NSThread.m:968)
9   libsystem_pthread.dylib         0x00000001f70a96cc _pthread_start + 148 (pthread.c:893)
10  libsystem_pthread.dylib         0x00000001f70a8ba4 thread_start + 8 (:-1)

Thread 3 name:
Thread 3:
0   libsystem_kernel.dylib          0x00000001e6e6c6ac select$DARWIN_EXTSN + 8 (:-1)
1   CoreFoundation                  0x00000001aa84b9d4 __CFSocketManager + 636 (CFSocket.c:1340)
2   libsystem_pthread.dylib         0x00000001f70a96cc _pthread_start + 148 (pthread.c:893)
3   libsystem_pthread.dylib         0x00000001f70a8ba4 thread_start + 8 (:-1)

Thread 4 name:
Thread 4:
0   libsystem_kernel.dylib          0x00000001e6e6bb48 mach_msg2_trap + 8 (:-1)
1   libsystem_kernel.dylib          0x00000001e6e7e008 mach_msg2_internal + 80 (mach_msg.c:201)
2   libsystem_kernel.dylib          0x00000001e6e7e248 mach_msg_overwrite + 388 (mach_msg.c:0)
3   libsystem_kernel.dylib          0x00000001e6e6c08c mach_msg + 24 (mach_msg.c:323)
4   libdispatch.dylib               0x00000001b1c21364 _dispatch_mach_send_and_wait_for_reply + 540 (mach.c:816)
5   libdispatch.dylib               0x00000001b1c216ec dispatch_mach_send_with_result_and_wait_for_reply + 60 (mach.c:2017)
6   libxpc.dylib                    0x00000001f70fb8b0 xpc_connection_send_message_with_reply_sync + 240 (connection.c:998)
7   Foundation                      0x00000001a4c6a574 __NSXPCCONNECTION_IS_WAITING_FOR_A_SYNCHRONOUS_REPLY__ + 16 (NSXPCConnection.m:223)
8   Foundation                      0x00000001a4bfd9bc -[NSXPCConnection _sendInvocation:orArguments:count:methodSignature:selector:withProxy:] + 2236 (NSXPCConnection.m:1678)
9   Foundation                      0x00000001a4bfc18c -[NSXPCConnection _sendSelector:withProxy:arg1:] + 116 (NSXPCConnection.m:1299)
10  Foundation                      0x00000001a4bfc0c4 _NSXPCDistantObjectSimpleMessageSend1 + 60 (NSXPCDistantObject.m:262)
11  Speech                          0x00000001d15b24b8 -[SFLocalSpeechRecognitionClient installedLanguagesWithSynchronousConnection:completion:] + 252 (SFLocalSpeechRecognitionClient.m:0)
12  Speech                          0x00000001d15ba9f4 +[SFSpeechAssetManager installedLanguages] + 180 (SFSpeechAssetManager.m:89)
13  Speech                          0x00000001d15a82e4 __72-[SFSpeechRecognitionTask _initWithRequest:queue:languageCode:taskHint:]_block_invoke + 240 (SFSpeechRecognitionTask.m:134)
14  libdispatch.dylib               0x00000001b1c044b4 _dispatch_call_block_and_release + 32 (init.c:1518)
15  libdispatch.dylib               0x00000001b1c05fdc _dispatch_client_callout + 20 (object.m:560)
16  libdispatch.dylib               0x00000001b1c0d694 _dispatch_lane_serial_drain + 672 (inline_internal.h:2632)
17  libdispatch.dylib               0x00000001b1c0e1e0 _dispatch_lane_invoke + 384 (queue.c:3940)
18  libdispatch.dylib               0x00000001b1c18e10 _dispatch_workloop_worker_thread + 652 (queue.c:6846)
19  libsystem_pthread.dylib         0x00000001f70a8df8 _pthread_wqthread + 288 (pthread.c:2618)
20  libsystem_pthread.dylib         0x00000001f70a8b98 start_wqthread + 8 (:-1)

Thread 5:
0   libsystem_pthread.dylib         0x00000001f70a8b90 start_wqthread + 0 (:-1)

Thread 6:
0   libsystem_pthread.dylib         0x00000001f70a8b90 start_wqthread + 0 (:-1)

Thread 7 name:
Thread 7:
0   libsystem_kernel.dylib          0x00000001e6e6bac4 semaphore_wait_trap + 8 (:-1)
1   caulk                           0x00000001f8a2288c caulk::mach::semaphore::wait_or_error() + 28 (mach_semaphore.cpp:131)
2   caulk                           0x00000001f8a22fc4 caulk::concurrent::details::worker_thread::run() + 56 (semaphore.cpp:98)
3   caulk                           0x00000001f8a2378c 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 (type_traits:3866)
4   libsystem_pthread.dylib         0x00000001f70a96cc _pthread_start + 148 (pthread.c:893)
5   libsystem_pthread.dylib         0x00000001f70a8ba4 thread_start + 8 (:-1)


Thread 0 crashed with ARM Thread State (64-bit):
    x0: 0x0000000000000000   x1: 0x0000000000000000   x2: 0x0000000000000000   x3: 0x0000000000000000
    x4: 0x00000001f6ff50f5   x5: 0x000000016d52b0d0   x6: 0x000000000000006e   x7: 0xffffffff00001500
    x8: 0xf174bd25897288fe   x9: 0xf174bd2789e4a13e  x10: 0x0000000000000200  x11: 0x000000000000000b
   x12: 0x000000000000000b  x13: 0x0000000000000000  x14: 0x0000000000000000  x15: 0x0000000000000000
   x16: 0x0000000000000148  x17: 0x00000002009629c0  x18: 0x0000000000000000  x19: 0x0000000000000006
   x20: 0x0000000000000103  x21: 0x0000000200962aa0  x22: 0x0000000201d123a0  x23: 0x0000000281e50010
   x24: 0x0000000000000001  x25: 0x0000000000000001  x26: 0x0000000000000001  x27: 0x0000000000000000
   x28: 0x00000001cb39b9e0   fp: 0x000000016d52b040   lr: 0x00000001f70af1ac
    sp: 0x000000016d52b020   pc: 0x00000001e6e72200 cpsr: 0x40001000
   esr: 0x56000080  Address size fault


Binary Images:
        0x1028d4000 -         0x102a53fff MyFirstApp arm64  <7ef40d9b333d3a06ae50b8ff35ce8ba1> /private/var/containers/Bundle/Application/53C5217A-2752-497D-9424-7F011A8D1499/MyFirstApp.app/MyFirstApp
        0x1a3b38000 -         0x1a3b7bc3f libobjc.A.dylib arm64e  <b3a78098c0fb3dcdb1ac0712762510db> /usr/lib/libobjc.A.dylib
        0x1a4bc8000 -         0x1a5512fff Foundation arm64e  <aa92cd58561a341492f4b4120298b39a> /System/Library/Frameworks/Foundation.framework/Foundation
        0x1aa780000 -         0x1aab64fff CoreFoundation arm64e  <42c5c91704473995b50fde4d132c2435> /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
        0x1ab8fb000 -         0x1abcc0fff CFNetwork arm64e  <35605de33723335a83d96f35f2989935> /System/Library/Frameworks/CFNetwork.framework/CFNetwork
        0x1ac90e000 -         0x1ae0d4fff UIKitCore arm64e  <7b942fa4cb7633759972f58c14492fb4> /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore
        0x1b1c02000 -         0x1b1c48fff libdispatch.dylib arm64e  <c663d847b94f3fb0925432edbc55315e> /usr/lib/system/libdispatch.dylib
        0x1b1c49000 -         0x1b1cc8fff libsystem_c.dylib arm64e  <82c0f938e2773165a61470151c651798> /usr/lib/system/libsystem_c.dylib
        0x1c0e39000 -         0x1c0f85fff AVFAudio arm64e  <52e7fdd92ab93a39b351e4ecabbebe1d> /System/Library/Frameworks/AVFAudio.framework/AVFAudio
        0x1c8b10000 -         0x1c8b92e4f dyld arm64e  <341bbf646034357e8aa6e1e4b988e03c> /usr/lib/dyld
        0x1d15a6000 -         0x1d15c8fff Speech arm64e  <f856204862c73b8ebe0428a6ac39f1ed> /System/Library/Frameworks/Speech.framework/Speech
        0x1e3620000 -         0x1e3628fff GraphicsServices arm64e  <03732ba5113235b4b09d8dd49807d246> /System/Library/PrivateFrameworks/GraphicsServices.framework/GraphicsServices
        0x1e6e6b000 -         0x1e6ea1ffb libsystem_kernel.dylib arm64e  <a5d3b72578c33e19a765cceb22355093> /usr/lib/system/libsystem_kernel.dylib
        0x1f6fe0000 -         0x1f6ff7ffb libc++abi.dylib arm64e  <e0dbf9459cc5305db096abc1cda9c8ca> /usr/lib/libc++abi.dylib
        0x1f70a8000 -         0x1f70b3fff libsystem_pthread.dylib arm64e  <b89b9a5b55d93e84b6d3c3da93c1cd39> /usr/lib/system/libsystem_pthread.dylib
        0x1f70ec000 -         0x1f712bfff libxpc.dylib arm64e  <be45e2e7648c3a609c57e63229b6cfe0> /usr/lib/system/libxpc.dylib
        0x1f8a20000 -         0x1f8a49fff caulk arm64e  <014ac97978303a37a079ff0e0f2b3032> /System/Library/PrivateFrameworks/caulk.framework/caulk

EOF
iOS Swift AVFafoundation Core-Audio

评论


答: 暂无答案