Go4Expert (http://www.go4expert.com/)
-   C# (http://www.go4expert.com/forums/c-sharp/)
-   -   "Recording a sound" Help (http://www.go4expert.com/forums/recording-sound-help-t12102/)

pb_ce85 15Jul2008 02:13

"Recording a sound" Help
Does anyone knows how can record a sound from an available microphone?

SaswatPadhi 14May2009 19:27

Re: "Recording a sound" Help
To help others with similar problem, I'm posting a solution though its late by 9 months :p

I would have achieved sound recording in C# by using mciSendStringA in winmm.dll.

First import the dll :
Code: c#

[DllImport("winmm.dll", EntryPoint = "mciSendStringA", CharSet = CharSet.Auto]
private static extern int mciSendString(string lpstrCommand, string lpstrReturnString, int uReturnLength, int hwndCallback);

Now, create a new device (named MyRecorder) :
Code: c#

mciSendString("open new type waveaudio alias MyRecorder", "" , 0, 0);

To start sound recording :
Code: c#

mciSendString("record MyRecorder", "" , 0, 0);

To save the recorded sound (to C:\MySound.wav):
Code: c#

mciSendString("save MyRecorder C:\\MySound.wav", "" , 0, 0);

To stop recording sound :
Code: c#

mciSendString("close MyRecorder", "" , 0, 0);

That's it !

For complete list of MCI Strings, go here : http://msdn.microsoft.com/en-us/libr...loband%29.aspx

I hope this post would be useful to many :smile:.

All times are GMT +5.5. The time now is 14:24.