首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Flutter (Dart):从麦克风获取/录制音频流,并立即播放(实时)

Flutter (Dart):从麦克风获取/录制音频流,并立即播放(实时)
EN

Stack Overflow用户
提问于 2018-09-25 22:46:39
回答 1查看 7.4K关注 0票数 7

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

有什么帮助或建议吗?

EN

回答 1

Stack Overflow用户

发布于 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

创建实例。

代码语言:javascript
复制
FlutterSound flutterSound = new FlutterSound();

正在使用监听程序启动记录器。

代码语言:javascript
复制
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);
});

停止记录器

代码语言:javascript
复制
String result = await flutterSound.stopRecorder();
print('stopRecorder: $result');

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

启动播放器

代码语言:javascript
复制
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);
        });
    }
});
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52501007

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档