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

Use same audio engine for player and recorder in IOS #1109

Open
parkjihwanjay opened this issue Oct 23, 2024 · 2 comments
Open

Use same audio engine for player and recorder in IOS #1109

parkjihwanjay opened this issue Oct 23, 2024 · 2 comments
Labels
enhancement New feature or request Not yet handled

Comments

@parkjihwanjay
Copy link

Is your feature request related to a problem? Please describe.
When I use flutter sound player and recorder for real time communication through server in IOS, the sound gets played through built-in-receiver, not built-in-speaker. I configured audio session initially like this, but it is same.

    await Permission.microphone.request();

    final session = await AudioSession.instance;

    await session.configure(AudioSessionConfiguration(
      avAudioSessionCategory: AVAudioSessionCategory.playAndRecord,
      avAudioSessionCategoryOptions:
          AVAudioSessionCategoryOptions.allowBluetooth | AVAudioSessionCategoryOptions.defaultToSpeaker,
      avAudioSessionMode: AVAudioSessionMode.voiceChat,
      avAudioSessionRouteSharingPolicy:
          AVAudioSessionRouteSharingPolicy.defaultPolicy,
      avAudioSessionSetActiveOptions: AVAudioSessionSetActiveOptions.none,
      androidAudioAttributes: const AndroidAudioAttributes(
        contentType: AndroidAudioContentType.speech,
        flags: AndroidAudioFlags.none,
        usage: AndroidAudioUsage.voiceCommunication,
      ),
      androidAudioFocusGainType: AndroidAudioFocusGainType.gain,
      androidWillPauseWhenDucked: true,
    ));

    await AVAudioSession().overrideOutputAudioPort(AVAudioSessionPortOverride.speaker);

    await session.setActive(true);

    await _recorder.openRecorder();
    await _player.openPlayer();

Describe the solution you'd like
To solve this problem, player and recorder have to use same audio engine in IOS and setVoiceProcessingEnabled as true of AVAudioInputNode as true before recording

    let inputNode: AVAudioInputNode
    try inputNode.setVoiceProcessingEnabled(true)

Describe alternatives you've considered
I don't the native code of flutter_sound, but it seems like player and recorder does not use same audio engine in IOS. That might be why sound plays in receiver rather than speaker.

I'd like to suppose player and recorder use same audio engine in IOS and setVoiceProcessingEnabled as true before recording.

Additional context
If there is solution to this problem, please let me know. Thanks : )

@parkjihwanjay parkjihwanjay added enhancement New feature or request Not yet handled labels Oct 23, 2024
@Larpoux
Copy link
Collaborator

Larpoux commented Oct 23, 2024

Actually Flutter Sound 9.x use the default mic and the default speaker. There is no possibility to select a specific mic and/or a specific speaker.
This is really something missing in 9.x.

I am currently working on Flutter Sound 10.x, and it will be possible in this future version to select the speaker and the mic.
Unfortunately this new release is far from being released. There is much work to do on this new version because everything is re-coded differently.
I expect to release an alpha version at the end of the year or beginning of next year, but only for web.
Port on mobiles and desktop will be later during 2025.

@parkjihwanjay
Copy link
Author

Then in 9.x, is there way to solve the problem that the sound is played through receiver rather than speaker when set to voiceChat mode?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Not yet handled
Projects
None yet
Development

No branches or pull requests

2 participants