我正在尝试使用C#开发语音记录器。我已经尝试了许多方法,比如NAudio、DirectX、Microsoft.Xna.Framework.Audio等。
所有的方法都得到了相同的结果。在停止录制后,输出文件mp3/wav会被保存。
mp3/wav文件在一开始就被创建了(没有任何内容-0字节)。
我正在尝试创建一个可以实时保存音频的应用程序。
所有的方法都得到了相同的结果。在停止录制后,输出文件mp3/wav会被保存。
mp3/wav文件在一开始就被创建了(没有任何内容-0字节)。
我正在尝试创建一个可以实时保存音频的应用程序。
private void StartRecording() {
this.WaveSource = new WaveInEvent { WaveFormat = new WaveFormat(44100, 1) };
this.WaveSource.DataAvailable += this.WaveSourceDataAvailable;
this.WaveSource.RecordingStopped += this.WaveSourceRecordingStopped;
this.WaveFile = new WaveFileWriter(@"C:\Sample.wav", this.WaveSource.WaveFormat);
this.WaveSource.StartRecording();
}
private void StopRecording() {
this.WaveSource.StopRecording();
}
void WaveSourceDataAvailable(object sender, WaveInEventArgs e) {
if (this.WaveFile != null) {
this.WaveFile.Write(e.Buffer, 0, e.BytesRecorded);
this.WaveFile.Flush();
}
}
void WaveSourceRecordingStopped(object sender, StoppedEventArgs e) {
if (this.WaveSource != null) {
this.WaveSource.Dispose();
this.WaveSource = null;
}
if (this.WaveFile != null) {
this.WaveFile.Dispose();
this.WaveFile = null;
}
}