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