以下是我的代码 已经可以实现格式转换了,但是我想把音频格式PCM 转换位 CCITT A-Law出现了一点问题
            NAudio.Wave.WaveFormat format = new NAudio.Wave.WaveFormat(8000, 8, 1);            format.Encoding = WaveFormatEncoding.ALaw;  //错误 1 无法对属性或索引器“NAudio.Wave.WaveFormat.Encoding”赋值 -- 它是只读的 C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\转换采样率\转换采样率\Program.cs 30 13 转换采样率            NAudio.Wave.WaveFileReader fileread = new WaveFileReader(@"E:\1.wav");
            NAudio.Wave.WaveStream wavestream = new WaveFormatConversionStream(format, fileread);
            NAudio.Wave.WaveFileWriter.CreateWaveFile(@"E:\2.wav", wavestream);
我看到 format.Encoding = WaveFormatEncoding.ALaw //它里面有个ALaw 的属性,但是赋值不了,想问你一下如何解决。我看源码看了一些,但是没找到。 
非常感谢了

解决方案 »

  1.   

    我在源代码里找到 public WaveFormat(int rate, int bits, int channels)
    {
                if (channels < 1)
                {
                    throw new ArgumentOutOfRangeException("Channels must be 1 or greater", "channels");
                }
    // minimum 16 bytes, sometimes 18 for PCM
    this.waveFormatTag = WaveFormatEncoding.Pcm;
    this.channels = (short)channels;
    this.sampleRate = rate;
    this.bitsPerSample = (short)bits;
    this.extraSize = 0;
                   
    this.blockAlign = (short)(channels * (bits / 8));
    this.averageBytesPerSecond = this.sampleRate * this.blockAlign;
    }
    this.waveFormatTag = WaveFormatEncoding.Pcm;  //已经把格式写死了把。。
    我试着 变成  this.waveFormatTag=WaveFormatEncoding.ALaw  但是编译的时候报错
    错误列表如下
    未处理 MmException
    AcmNostPossible calling acmStaeam Open文件流是打开的?
      

  2.   

    http://www.codeproject.com/KB/security/g711audio.aspx