gpt4 book ai didi

audio - flutter ( Dart ): Get/Record audio stream from microphone and play it back immediately (real-time)

转载 作者:IT王子 更新时间:2023-10-29 06:34:31 27 4
gpt4 key购买 nike

我需要能够从麦克风捕获音频流,然后将其作为参数传递或立即读取,以便将其作为音频播放。要在任何其他框架中实现这一点,您可以使用优秀的工具和功能,但我需要在 Flutter 上归档该功能。

有什么帮助或建议吗?

最佳答案

请试试这个包 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);
});
}
});

关于audio - flutter ( Dart ): Get/Record audio stream from microphone and play it back immediately (real-time),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52501007/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com