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
);
后来发现需要修改配置,如下,摘自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,
// ),
));
先初始化配置,再开始录音,成功