Record and play audio at the same time with Core audio Api

  • Thread starter Thread starter hungcui
  • Start date Start date
H

hungcui

Guest
Hi everyone!

I have a code can Record and play audio at the same time with Naudio:

public partial class MainWindow : Window
{
private WaveIn recorder;
private BufferedWaveProvider bufferedWaveProvider;
private SavingWaveProvider savingWaveProvider;
private WaveOut player;

public MainWindow()
{
InitializeComponent();
}

private void OnStartRecordingClick(object sender, RoutedEventArgs e)
{
// set up the recorder
recorder = new WaveIn();
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();
player.Init(savingWaveProvider);

// begin playback & record
player.Play();
recorder.StartRecording();
}

private void RecorderOnDataAvailable(object sender, WaveInEventArgs waveInEventArgs)
{
bufferedWaveProvider.AddSamples(waveInEventArgs.Buffer,0, waveInEventArgs.BytesRecorded);
}

private void OnStopRecordingClick(object sender, RoutedEventArgs e)
{
// stop recording
recorder.StopRecording();
// stop playback
player.Stop();
// finalise the WAV file
savingWaveProvider.Dispose();
}
}


And with core api how to do it. Thanks you!

Continue reading...
 
Back
Top