Flutter (Dart): Get/Record audio stream from microphone and play it back immediately (real-time)
Asked Answered
T

1

9

I need to be able to capture a stream of audio from the microphone and then pass it as argument or read it immediately in order to play it back as audio. To implement this in any other framework there are excellent tools and functions you can use but I need to archive that functionality on Flutter.

Any help or suggestions?

Thury answered 25/9, 2018 at 14:46 Comment(9)
Check out the audio_recorder and audioplayer packages.Byandby
hi @KirollosMorkos, I was playing around with this one medcorder_audio, but thanks for your recommendations! I will try and update the post here with any outcomeThury
@Thury did you find anything. I am working on video call fetcher so I want to switch audio to speaker phoneSanction
Hi @Jigar, yet no because I was off, but I plan this weekend to finish that task. I will reply here for sureThury
thanks Let me know @ThurySanction
Any package for flutter web?Malta
Hi, Did you find solution for this?Jellied
Check this example of the flutter_sound library: github.com/dooboolab/flutter_sound/blob/master/flutter_sound/…Mohammed
Any crossplatform solution? Android/iOS/Web/MacOS/Windows?Token
A
6

Please try this package flutter_sound.
https://github.com/dooboolab/flutter_sound
Here is reference link
https://medium.com/flutterpub/flutter-sound-plugin-audio-recorder-player-e5a455a8beaf

Creating instance.

FlutterSound flutterSound = new FlutterSound();

Starting recorder with listener.

String path = await flutterSound.startRecorder(null);
print('startRecorder: $path');

_recorderSubscription = flutterSound.onRecorderStateChanged.listen((e) {
  DateTime date = new DateTime.fromMillisecondsSinceEpoch(e.currentPosition.toInt());
  String txt = DateFormat('mm:ss:SS', 'en_US').format(date);
});

Stop recorder

String result = await flutterSound.stopRecorder();
print('stopRecorder: $result');

if (_recorderSubscription != null) {
    _recorderSubscription.cancel();
    _recorderSubscription = null;
}

Start player

String path = await flutterSound.startPlayer(null);
print('startPlayer: $path');

_playerSubscription = flutterSound.onPlayerStateChanged.listen((e) {
    if (e != null) {
        DateTime date = new DateTime.fromMillisecondsSinceEpoch(e.currentPosition.toInt());
        String txt = DateFormat('mm:ss:SS', 'en_US').format(date);
        this.setState(() {
            this._isPlaying = true;
            this._playerTxt = txt.substring(0, 8);
        });
    }
});
Adest answered 6/6, 2019 at 5:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.