await recorder?.startRecorder(toFile:"")
存儲到本地文件的沒問題,采集音頻流的方式錄音就一直報錯
await recorder?.openRecorder();
var recordingDataController = StreamController<Food>();
_mRecordingDataSubscription =
recordingDataController.stream.listen((buffer) {
if (buffer is FoodData) {
print('buffer ---- $buffer');
}
});
await recorder?.startRecorder(
toStream: recordingDataController.sink,
codec: Codec.pcm16,
audioSource: AudioSource.microphone
);
后來發(fā)現(xiàn)需要修改配置濒持,如下,摘自github上作者的demo
final session = await AudioSession.instance;
await session.configure(const AudioSessionConfiguration(
avAudioSessionCategory: AVAudioSessionCategory.playAndRecord,
avAudioSessionCategoryOptions: AVAudioSessionCategoryOptions.defaultToSpeaker,
avAudioSessionMode: AVAudioSessionMode.spokenAudio,
avAudioSessionRouteSharingPolicy:
AVAudioSessionRouteSharingPolicy.defaultPolicy,
avAudioSessionSetActiveOptions: AVAudioSessionSetActiveOptions.none,
// androidAudioAttributes: AndroidAudioAttributes(
// contentType: AndroidAudioContentType.speech,
// flags: AndroidAudioFlags.none,
// usage: AndroidAudioUsage.voiceCommunication,
// ),
));
先初始化配置,再開始錄音,成功