簡體   English   中英

Flutter (Dart):從麥克風獲取/錄制音頻流並立即播放(實時)

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM