How to store a .wav file in Windows 10 with NAudio

情到浓时终转凉″ 提交于 2019-12-25 09:04:48

问题


I'm trying to store my 16000hz 16bit mono PCM audio bytes to a wav file in a Windows 10 app.

NAudio normaly has a WavFileWriter, but it seems to be gone in the Windows 10 version. I can only seem to find access to new WaveFormat(16000, 16, 1); from https://www.nuget.org/packages/NAudio/1.7.3/

Is there a stream I can use to create the Wav file or its bytes?


回答1:


I suspect that NAudio removed WavFileWriter because there's now a substitute in the standard UWP API, in the Windows.Media.Audio namespace. What you should use now is something like this:

MediaEncodingProfile.CreateWav(AudioEncodingQuality.High);

Documentation for the api: link




回答2:


Yes the reason WaveFileWriter is not available in UWP is because you can't use the old File APIs in UWP so WaveFileWriter would need to be re-written to work in UWP.

As Tommaso has pointed out, UWP does actually have the ability to create WAV files using AudioGraph but it's options are very limited, so you may not be able to specify the exact sample rate you want. You might find that AudioEncodingQuality.Low uses a lower sample rate with WAV. (I can't remember off the top of my head)



来源:https://stackoverflow.com/questions/39474257/how-to-store-a-wav-file-in-windows-10-with-naudio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!