我需要能够从麦克风捕获音频流,然后将其作为参数传递或立即读取,以便将其作为音频播放。要在任何其他框架中实现这一点,您可以使用一些优秀的工具和函数,但我需要在Flutter上归档这些功能。
有什么帮助或建议吗?
发布于 2019-06-06 13:18:13
请尝试这个包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);
});
}
});https://stackoverflow.com/questions/52501007
复制相似问题