简体   繁体   English

录制音频NAudio库的错误的.wav格式

[英]wrong .wav format recording audio NAudio library

im having problems when trying to record sound from microphone in my wpf application. 即时通讯在我的wpf应用程序中尝试从麦克风录制声音时遇到问题。 here's my code: 这是我的代码:

    public NAudio.Wave.WaveFileWriter wav_writer = null;  // snemanje
    public WaveIn strim;

    private void snemanje_Click(object sender, RoutedEventArgs e)
    {
        strim = new WaveIn();
        strim.WaveFormat = new WaveFormat(44100, 0);

        SaveFileDialog svg = new SaveFileDialog();
        svg.Filter = "*WAV File (*.wav)|*.wav;*";
        svg.ShowDialog();

        strim.DataAvailable += new EventHandler<WaveInEventArgs>(waveInStream_DataAvailable);
        wav_writer = new WaveFileWriter(svg.FileName, strim.WaveFormat);
        strim.StartRecording();
    }


    public void waveInStream_DataAvailable(object sender, WaveInEventArgs e)
    {
        wav_writer.WriteData(e.Buffer, 0, e.BytesRecorded);
        wav_writer.Flush();
    }

everything works perfectly and the file is saved in the projects location, but i can not oppen it. 一切正常,文件保存在项目位置,但我不能拒绝它。 it says that it is a wave file but everytime i want to play it, it says that i must find codecs for playing in that format (but there arent any). 它说它是一个wave文件,但是每次我要播放它时,它都说我必须找到要以这种格式播放的编解码器(但是那里没有任何文件)。

Don't create a WaveFormat with 0 channels. 请勿创建具有0个通道的WaveFormat。 You should use 1 for mono or 2 for stereo. 您应将1用于单声道或将2用于立体声。

 // create a mono 44.1kHz wave format
 new WaveFormat(44100, 1);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM