Canardoux / flutter_sound

Flutter plugin for sound. Audio recorder and player.
Mozilla Public License 2.0
850 stars 553 forks source link

[BUG]: EnableVoiceProcessing: true (on iOS) #1019

Closed Larpoux closed 3 months ago

Larpoux commented 3 months ago

Flutter Sound Version :

9.3.8


Severity

Platforms you faced the error


Describe the bug When I call

if (![outputNode setVoiceProcessingEnabled:YES error:&err])

then, later, when I call

[engine connect: playerNode to: outputNode format: outputFormat];

I get an exception "required condition is false: IsFormatSampleRateAndChannelCountValid(format)"

I am not sure that this is tied with integration of the PullRequest #1000

To Reproduce Steps to reproduce the behavior:

  1. Start the Demo Example "Live Playback Without back pressure"
  2. Check "Enable Voice Processing
  3. Hit the Play button

Logs!!!!

AVAEInternal.h:76 required condition is false: [AVAudioEngineGraph.mm:2 128:_Connect: (IsFormatSampleRateAndChannelCountValid(format))]
*** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: IsFormatSampleRateAndChannelCountValid(format)'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000018048d8a8 __exceptionPreprocess + 172
    1   libobjc.A.dylib                     0x000000018008409c objc_exception_throw + 56
    2   CoreFoundation                      0x000000018048d74c +[NSException raise:format:] + 0
    3   AVFAudio                            0x00000001beea63e4 _Z19AVAE_RaiseExceptionP8NSStringz + 48
    4   AVFAudio                            0x00000001beee9630 _ZN18AVAudioEngineGraph8_ConnectEP19AVAudioNodeImplBaseS1_jjP13AVAudioFormat + 308
    5   AVFAudio                            0x00000001bef7c438 _ZN17AVAudioEngineImpl7ConnectEP11AVAudioNodeS1_mmP13AVAudioFormat + 1428
    6   AVFAudio                            0x00000001bef7337c -[AVAudioEngine connect:to:format:] + 124
    7   Runner                              0x0000000104527268 -[AudioEngine init:] + 796
    8   Runner                              0x0000000104524a1c -[FlautoPlayer startPlayerCodec:fromURI:fromDataBuffer:channels:sampleRate:] + 280
    9   Runner                              0x000000010451ec70 -[FlutterSoundPlayer startPlayer:result:] + 1192
    10  Runner                              0x0000000104520b08 -[FlutterSoundPlayerManager handleMethodCall:result:] + 1196
    11  Flutter                             0x00000001092123f0 __45-[FlutterMethodChannel setMethodCallHandler:]_block_invoke + 164
    12  Flutter                             0x0000000108c44300 ___ZN7flutter25PlatformMessageHandlerIos21HandlePlatformMessageENSt3_fl10unique_ptrINS_15PlatformMessageENS1_14default_deleteIS3_EEEE_block_invoke + 108
    13  libdispatch.dylib                   0x00000001047c80f0 _dispatch_call_block_and_release + 24
    14  libdispatch.dylib                   0x00000001047c993c _dispatch_client_callout + 16
    15  libdispatch.dylib                   0x00000001047d95e4 _dispatch_main_queue_drain + 1228
    16  libdispatch.dylib                   0x00000001047d9108 _dispatch_main_queue_callback_4CF + 40
    17  CoreFoundation                      0x00000001803ee1b4 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
    18  CoreFoundation                      0x00000001803e88cc __CFRunLoopRun + 1936
    19  CoreFoundation                      0x00000001803e7d28 CFRunLoopRunSpecific + 572
    20  GraphicsServices                    0x000000018e7cdbc0 GSEventRunModal + 160
    21  UIKitCore                           0x00000001852bafdc -[UIApplication _run] + 868
    22  UIKitCore                           0x00000001852bec54 UIApplicationMain + 124
    23  Runner                              0x00000001045152b4 main + 100
    24  dyld                                0x0000000104741558 start_sim + 20
    25  ???                                 0x00000001048fe0e0 0x0 + 4371505376
    26  ???                                 0xb007000000000000 0x0 + 12684106875512291328
)
libc++abi: terminating due to uncaught exception of type NSException
timcschmidt commented 3 months ago

Taking a look.

timcschmidt commented 3 months ago

Likely related to https://stackoverflow.com/questions/74516660/ios-app-crashes-with-required-condition-is-false-isformatsamplerateandchannelc.

My basic understanding is that the microphone is not available. You would have to signal/request the correct playing category via AVAudioSession to AVAudioSessionCategoryPlayAndRecord and also react to any changes in the singleton's state (i.e. when some other app switches the category).

There is a sample project available from apple that demonstrates this (though it is in swift)

github-actions[bot] commented 3 months ago

This issue is stale because it has been open 365 days with no activity. Leave a comment or this will be closed in 7 days.

Larpoux commented 3 months ago

EnableVoiceProcessing is only when recording from mic. Not relevant for the Player.