Jumps in final file when recording wit naudio and C#


Jumps in final file when recording wit naudio and C#



I have developed a win forms application using Naudio and C# it has two buttons, one for start recording and other for stop recording. My problem is that the final audio file (WAV) has jumps, and with jumps, I mean that some seconds are lost in the middle of the recording, for example, if I record a narration which text is :



“the fox jumps over the lazy dog” In the wav you listen something like “the x jum over the og” or “the fox ps the la dog” I googled a lot to find a solution and did not find yet.



Please help me to solve



This is my code:


IWaveIn wi;
WaveFileWriter wfw;
int length;
String NomArch;
int idLamina;
int idPlan;
OleDbConnection connection;
string DBPath;
string pathApp;

Boolean Cargando = true;
void wi_StartRecording(String pNomArch = @"C:tempsonido.wav")
{
wi = new WaveIn(WaveCallbackInfo.FunctionCallback());
}
wi.WaveFormat = new WaveFormat(44100, 1);
wi.DataAvailable += new EventHandler<WaveInEventArgs>(wi_DataAvailable);
wi.RecordingStopped += new EventHandler<StoppedEventArgs>(wi_RecordingStopped);

wfw = new WaveFileWriter(pNomArch, wi.WaveFormat);

wi.StartRecording();
}

void wi_StopRecording()
{
wi.StopRecording();
wfw.Dispose();
}

void wi_DataAvailable(object sender, WaveInEventArgs e)
{
wfw.Write(e.Buffer, 0, e.BytesRecorded);
wfw.Flush();

int seconds = (int)(wfw.Length /
wfw.WaveFormat.AverageBytesPerSecond);
length = seconds;
}

void wi_RecordingStopped(object sender, EventArgs e)
{
if (wi != null)
{
wi.Dispose();
}
if (wfw != null)
{
wfw.Close();
}
}

private void btnRecord_Click(object sender, EventArgs e)
{
wi_StartRecording(NomArch);
btnStop.Visible = true;
btnRecord.Visible = false;
btnStop.Focus();
}

private void btnStop_Click(object sender, EventArgs e)
{
wi_StopRecording();
btnRecord.Visible = true;
btnStop.Visible = false;
}









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Opening a url is failing in Swift

Export result set on Dbeaver to CSV