Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# recording audio from soundcard [closed]

Tags:

I want to record audio from my soundcard(output). I've found CSCore on codeplex but I could not find any examples. Does anyone know how to use the library to record audio from my soundcard and write the record data onto the harddrive? Or does anyone know a few tutorials on that library?

like image 512
user2741085 Avatar asked Sep 15 '13 12:09

user2741085


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

What does == mean in C?

The equal-to operator ( == ) returns true if both operands have the same value; otherwise, it returns false . The not-equal-to operator ( !=

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.


1 Answers

Take a look at the CSCore.SoundIn namespace. The WasapiLoopbackCapture class is able to record directly from any output device. But keep in mind that WasapiLoopbackCapture is only available since Windows Vista.

EDIT: This code should work for you.

using CSCore; using CSCore.SoundIn; using CSCore.Codecs.WAV;  ...  using (WasapiCapture capture = new WasapiLoopbackCapture()) {     //if nessesary, you can choose a device here     //to do so, simply set the device property of the capture to any MMDevice     //to choose a device, take a look at the sample here: http://cscore.codeplex.com/      //initialize the selected device for recording     capture.Initialize();      //create a wavewriter to write the data to     using (WaveWriter w = new WaveWriter("dump.wav", capture.WaveFormat))     {         //setup an eventhandler to receive the recorded data         capture.DataAvailable += (s, e) =>             {                 //save the recorded audio                 w.Write(e.Data, e.Offset, e.ByteCount);             };          //start recording         capture.Start();          Console.ReadKey();          //stop recording         capture.Stop();     } } 
like image 93
Florian Avatar answered Oct 10 '22 09:10

Florian