0
我使用naudio.Following是代碼初始化n音訊試圖記錄用戶的語音中UWP捕獲並寫入到磁盤:錄音講話n音訊
sourcestream = new WasapiCaptureRT();
sourcestream.WaveFormat = new WaveFormat(8000, 8, 1);
sourcestream.DataAvailable += OnDataAvailable;
sourcestream.RecordingStopped += OnRecordingStopped;
sourcestream.StartRecording();
file = await KnownFolders.MusicLibrary.CreateFileAsync("audio.wav", CreationCollisionOption.ReplaceExisting);
MediaEncodingProfile.CreateWav(AudioEncodingQuality.Auto);
memorystream = await file.OpenStreamForWriteAsync();
writer = new WaveFileWriterRT(memorystream, sourcestream.WaveFormat);
sourcestream.StartRecording();
但是,當執行涉及到
memorystream = await file.OpenStreamForWriteAsync();
則拋出異常並執行進到下面的代碼:
DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
UnhandledException += (sender, e) =>
{
if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();
};
}
的excepti在代碼是
不支持的波形格式
我試圖做的控制檯應用程序相同的,一切工作正常。但是當我嘗試在UWP中完成時,會顯示上述錯誤。
這個錯誤的原因是什麼?
感謝。我通過設置採樣率爲48000工作。但不知何故音頻錄製在uwp for windows 10中不起作用。文件被保存但沒有任何記錄。 – Dipumon
@Dipumon,在我的回覆中嘗試了更新。 –