像费率这样的要求应该是16000
public voID ConvertToWMA(string tempfilePath,string tempfilename,string audioType) { WaveFormat form = new WaveFormat(16000,16,1); using (WmaStream str = new WmaStream(tempfilePath + tempfilename,form)) { string profileData; using (StreamReader reader = new StreamReader(file.OpenRead("audio.prx"))) { profileData = reader.ReadToEnd(); } IWMProfileManager profileManager; IWMProfile wmProfile = null; profileManager = WM.CreateProfileManager(); profileManager.LoadProfileByData(profileData,out wmProfile); WMProfile wmp = new WMProfile(str.Profile); NAudio.windowsMediaFormat.WmaWriter ww = new NAudio.windowsMediaFormat.WmaWriter(new fileStream(@"D:\wma\conv\test.wma",fileMode.Create),form,wmProfile); byte[] buff = null; int read = 0; buff = new byte[form.AverageBytesPerSecond]; read = str.Read(buff,buff.Length); while ((read > 0)) { ww.Write(buff,read); read = str.Read(buff,buff.Length); } } }
如何摆脱这个问题.有人请帮帮我..
解决方法{ var temp = tempfilePath + tempfilename; using (var reader = new MediaFoundationReader(temp)) { // Create a wave format for 16-bit pcm at 8000 samples per second. int channels = reader.WaveFormat.Channels; int rate = 8000; int rawsize = 2; int blockalign = rawsize * channels; // this is the size of one sample. int bytespersecond = rate * blockalign; //MediaFoundationEncoder.enc(reader,"test.mp3"); var mIDformat = WaveFormat.CreateCustomFormat(WaveFormatEnCoding.Pcm,rate,channels,bytespersecond,blockalign,rawsize * 8); // And a conversion stream to turn input into 16-bit PCM. //var mIDstream = new MediaFoundationResampler(reader,mIDformat); // var outstream = new PcmToALawConversionStream(mIDstream); // var outstream = new PcmToALawConversionStream(mIDstream); //var converted16Bit = new SampletoWaveProvIDer16(mixer);// // Now for MP3,we need to upsample to 44.1kHz. Use MediaFoundationResampler using (var resampled = new MediaFoundationResampler( reader,mIDformat)) { var outstream = new PcmToALawConversionStream(resampled); // var desiredBitRate = 16000; // ask for lowest available bitrate //MediaFoundationEncoder.EncodetoWma(outstream,// "mixedtets10.wma",desiredBitRate); WavefileWriter.CreateWavefile("mixedtets10.wma",outstream); //NAudio.windowsMediaFormat.WmaWriter ww = new NAudio.windowsMediaFormat.WmaWriter(new fileStream(@"D:\wma\conv\test1.wma",mIDformat,outstream); } // NAudio.windowsMediaFormat.WmaWriter ww = new NAudio.windowsMediaFormat.WmaWriter(new fileStream(@"D:\wma\conv\test1.wma",outstream); //NAudio.windowsMediaFormat.WmaWriter Ww= // The output stream is our custom stream. //var outstream = new PcmToALawConversionStream(mIDstream); } }总结
以上是内存溢出为你收集整理的c# – wma使用Naudio压缩音频文件引发错误全部内容,希望文章能够帮你解决c# – wma使用Naudio压缩音频文件引发错误所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)