c# – wma使用Naudio压缩音频文件引发错误

c# – wma使用Naudio压缩音频文件引发错误,第1张

概述这里我有一些编码wma音频文件的代码..它工作得很好.但是把文件上传到服务器,发生了一些错误.它显示输出文件应该满足 像费率这样的要求应该是16000 public void ConvertToWMA(string tempFilePath, string tempFileName, string audioType) { WaveFormat form = n 这里我有一些编码wma音频文件的代码..它工作得很好.但是把文件上传到服务器,发生了一些错误.它显示输出文件应该满足
像费率这样的要求应该是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压缩音频文件引发错误所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1232202.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存