MicrosoftDocs / CommunityToolkit

The Official Docs for the Community Toolkits
https://learn.microsoft.com/dotnet/communitytoolkit
Creative Commons Attribution 4.0 International
109 stars 88 forks source link

SpeechToText iOS required condition is false: IsFormatSampleRateAndChannelCountValid(format) #454

Open eeadie opened 3 weeks ago

eeadie commented 3 weeks ago

Using SpeechToText ListenAsync on iOS:

SpeechToTextResult speechToTextResult = await SpeechToText.ListenAsync(CultureInfo.CurrentCulture, new Progress<string>(partialText => { RecognitionText += partialText + " "; }), cancellationToken);

I am receiving the following error:

Objective-C exception thrown. Name: com.apple.coreaudio.avfaudio Reason: required condition is false: IsFormatSampleRateAndChannelCountValid(format) Native stack trace: 0 CoreFoundation 0x00007ff80049b761 exceptionPreprocess + 242 1 libobjc.A.dylib 0x00007ff800063904 objc_exception_throw + 48 2 CoreFoundation 0x00007ff80049b56b +[NSException raise:format:] + 0 3 AVFAudio 0x00007ff846197929 _Z19AVAE_RaiseExceptionP8NSStringz + 156 4 AVFAudio 0x00007ff8461f2e90 _ZN17AUGraphNodeBaseV318CreateRecordingTapEmjP13AVAudioFormatU13block_pointerFvP16AVAudioPCMBufferP11AVAudioTimeE + 766 5 AVFAudio 0x00007ff84625f703 -[AVAudioNode installTapOnBus:bufferSize:format:block:] + 1456 6 libxamarin-dotnet-debug.dylib 0x000000010e3c5099 xamarin_dyn_objc_msgSend + 217 7 ??? 0x000000010ce5aea7 0x0 + 4511346343 8 libmonosgen-2.0.dylib 0x000000010f25b270 ves_pinvoke_method + 544 9 libmonosgen-2.0.dylib 0x000000010f24bd3c mono_interp_exec_method + 4284 10 libmonosgen-2.0.dylib 0x000000010f249383 interp_runtime_invoke + 259 11 libmonosgen-2.0.dylib 0x000000010f3307dd mono_runtime_try_invoke + 157 12 libmonosgen-2.0.dylib 0x000000010f333bae mono_runtime_invoke + 478 13 FireWatch.MobileApp 0x000000010c71a958 _ZL30native_to_managed_trampoline_9P11objc_objectP13objc_selectorPP11_MonoMethodj + 280 14 FireWatch.MobileApp 0x000000010c71b189 -[__MonoMac_NSAsyncSynchronizationContextDispatcher xamarinApplySelector] + 41 15 Foundation 0x00007ff800ea5790 NSThreadPerformPerform + 178 16 CoreFoundation 0x00007ff8003f8283 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 17 CoreFoundation 0x00007ff8003f81c5 CFRunLoopDoSource0 + 157 18 CoreFoundation 0x00007ff8003f79c2 CFRunLoopDoSources0 + 215 19 CoreFoundation 0x00007ff8003f20f7 __CFRunLoopRun + 919 20 CoreFoundation 0x00007ff8003f197d CFRunLoopRunSpecific + 557 21 GraphicsServices 0x00007ff80fe9d08f GSEventRunModal + 137 22 UIKitCore 0x00007ff805bbb53d -[UIApplication _run] + 972 23 UIKitCore 0x00007ff805bbffab UIApplicationMain + 123 24 libxamarin-dotnet-debug.dylib 0x000000010e37f50a xamarin_UIApplicationMain + 58 25 libmonosgen-2.0.dylib 0x000000010f25c765 do_icall + 341 26 libmonosgen-2.0.dylib 0x000000010f25aef7 do_icall_wrapper + 295 27 libmonosgen-2.0.dylib 0x000000010f24bc16 mono_interp_exec_method + 3990 28 libmonosgen-2.0.dylib 0x000000010f249383 interp_runtime_invoke + 259 29 libmonosgen-2.0.dylib 0x000000010f32f6f8 mono_runtime_invoke_checked + 136 30 libmonosgen-2.0.dylib 0x000000010f33703b mono_runtime_exec_main_checked + 107 31 libmonosgen-2.0.dylib 0x000000010f19bb62 mono_jit_exec + 354 32 libxamarin-dotnet-debug.dylib 0x000000010e3c3bea xamarin_main + 1898 33 FireWatch.MobileApp 0x000000010c7b13d4 main + 68 34 dyld 0x000000010d2023e0 start_sim + 10 35 ??? 0x000000010dc87386 0x0 + 4526207878

Occurs on both the emulator and native phone. Any ideas what could be causing this?

bijington commented 3 weeks ago

Did you initialize the library as per our documentation: https://learn.microsoft.com/dotnet/communitytoolkit/maui/essentials/speech-to-text?tabs=ios

eeadie commented 3 weeks ago

@bijington yes I did. Permissions in Info.plist, call to speechToText.RequestPermissions(cancellationToken) works. Calling ListenAsync throws the error.

bijington commented 3 weeks ago

@VladislavAntonyuk any thoughts on why this might occur?

VladislavAntonyuk commented 3 weeks ago

At least I found multiple posts with this issue: microphone is not available or another active session already uses microphone: https://forums.developer.apple.com/forums/thread/65656