开始和结束音频

时间:2018-05-14 05:10:24

标签: c# record naudio

我开始编程音频处理。我的问题是记录并保存到wav文件。目前我在使用“输入”完成录制时工作正常。但是当我沉默的时候,当我说并结束时,我希望声音开始!有什么办法请帮帮我,拜托! - 代码:

class Program
{
    static WaveFileWriter wavefile;
    static void Main(string[] args)
    {
        Console.WriteLine("Start Recording....");
        WaveInEvent waveSource = new WaveInEvent();
        waveSource.WaveFormat = new WaveFormat(16000, 1);
        waveSource.DataAvailable += new EventHandler<WaveInEventArgs>(waveSource_DataAvailable);
        string tempFile = (@"e:/Test/testrecord.wav");
        wavefile = new WaveFileWriter(tempFile, waveSource.WaveFormat);
        waveSource.StartRecording();
Console.WriteLine("Press Enter to stop");
        Console.ReadLine();
        waveSource.StopRecording();
    }

    static void waveSource_DataAvailable(object sender, WaveInEventArgs e)
    {
        wavefile.WriteData(e.Buffer, 0, e.BytesRecorded);
    }
}
}

0 个答案:

没有答案