H
hungcui
Guest
Hi everyone!
I record and play audio at the same time with NAudio. This code:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using NAudio.Wave;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
private WaveIn recorder;
private BufferedWaveProvider bufferedWaveProvider;
private SavingWaveProvider savingWaveProvider;
private WaveOut player;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
numericUpDown1.Value = 1;
numericUpDown1.DecimalPlaces = 1;
numericUpDown1.Increment = 0.1M;
numericUpDown1.Maximum = 1;
numericUpDown1.Minimum = 0;
}
private void button1_Click(object sender, EventArgs e)
{
recorder = new WaveIn();
recorder.BufferMilliseconds = 20;
recorder.DataAvailable += RecorderOnDataAvailable;
// set up our signal chain
bufferedWaveProvider = new BufferedWaveProvider(recorder.WaveFormat);
savingWaveProvider = new SavingWaveProvider(bufferedWaveProvider, "temp.wav");
// set up playback
player = new WaveOut { DesiredLatency = 100};
player.Init(savingWaveProvider);
//Console.Write(player);
// begin playback & record
player.Volume = 1;
player.Play();
recorder.StartRecording();
}
private void RecorderOnDataAvailable(object sender, WaveInEventArgs e)
{
bufferedWaveProvider.AddSamples(e.Buffer, 0, e.BytesRecorded);
}
private void button3_Click(object sender, EventArgs e)
{
recorder.StopRecording();
player.Stop();
savingWaveProvider.Dispose();
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
player.Volume = (float)numericUpDown1.Value;
}
}
}
In bufferedWaveProvider.AddSamples mabye data put in E.buffer and how to show that data to a Lable or Textbox. I tried "Tostring" but this is return System.Byte[]. Please help me!
Continue reading...
I record and play audio at the same time with NAudio. This code:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using NAudio.Wave;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
private WaveIn recorder;
private BufferedWaveProvider bufferedWaveProvider;
private SavingWaveProvider savingWaveProvider;
private WaveOut player;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
numericUpDown1.Value = 1;
numericUpDown1.DecimalPlaces = 1;
numericUpDown1.Increment = 0.1M;
numericUpDown1.Maximum = 1;
numericUpDown1.Minimum = 0;
}
private void button1_Click(object sender, EventArgs e)
{
recorder = new WaveIn();
recorder.BufferMilliseconds = 20;
recorder.DataAvailable += RecorderOnDataAvailable;
// set up our signal chain
bufferedWaveProvider = new BufferedWaveProvider(recorder.WaveFormat);
savingWaveProvider = new SavingWaveProvider(bufferedWaveProvider, "temp.wav");
// set up playback
player = new WaveOut { DesiredLatency = 100};
player.Init(savingWaveProvider);
//Console.Write(player);
// begin playback & record
player.Volume = 1;
player.Play();
recorder.StartRecording();
}
private void RecorderOnDataAvailable(object sender, WaveInEventArgs e)
{
bufferedWaveProvider.AddSamples(e.Buffer, 0, e.BytesRecorded);
}
private void button3_Click(object sender, EventArgs e)
{
recorder.StopRecording();
player.Stop();
savingWaveProvider.Dispose();
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
player.Volume = (float)numericUpDown1.Value;
}
}
}
In bufferedWaveProvider.AddSamples mabye data put in E.buffer and how to show that data to a Lable or Textbox. I tried "Tostring" but this is return System.Byte[]. Please help me!
Continue reading...