Flutter (Dart): получить / записать аудиопоток с микрофона и немедленно воспроизвести его (в режиме реального времени) - PullRequest
0 голосов
/ 25 сентября 2018

Мне нужно иметь возможность захватить поток аудио с микрофона, а затем передать его в качестве аргумента или сразу же прочитать его, чтобы воспроизвести его как аудио.Для реализации этого в любой другой среде есть отличные инструменты и функции, которые вы можете использовать, но мне нужно заархивировать эту функциональность на Flutter.

Любая помощь или предложения?

1 Ответ

0 голосов
/ 06 июня 2019

Пожалуйста, попробуйте этот пакет flutter_sound.
https://github.com/dooboolab/flutter_sound
Ссылочная ссылка
https://medium.com/flutterpub/flutter-sound-plugin-audio-recorder-player-e5a455a8beaf

Создание экземпляра.

FlutterSound flutterSound = new FlutterSound();

Запуск рекордера со слушателем.

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);
});

Остановка записи

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

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

Запуск проигрывателя

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);
        });
    }
});
...