![](/img/trans.png)
[英]FLUTTER: I want to record the stream of microphone and play it immediately
[英]Flutter (Dart): Get/Record audio stream from microphone and play it back immediately (real-time)
我需要能够从麦克风捕获音频流,然后将其作为参数传递或立即读取,以便将其作为音频播放。 要在任何其他框架中实现这一点,您可以使用出色的工具和功能,但我需要在 Flutter 上存档该功能。
任何帮助或建议?
请试试这个包 flutter_sound。
https://github.com/doobolab/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);
});
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.