1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

"Recording a sound" Help

Discussion in 'C#' started by pb_ce85, Jul 14, 2008.

  1. pb_ce85

    pb_ce85 New Member

    Hello
    Does anyone knows how can record a sound from an available microphone?
    Thanks
     
  2. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    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:
    [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:
    mciSendString("open new type waveaudio alias MyRecorder", "" , 0, 0);
    To start sound recording :
    Code:
    mciSendString("record MyRecorder", "" , 0, 0);
    To save the recorded sound (to C:\MySound.wav):
    Code:
    mciSendString("save MyRecorder C:\\MySound.wav", "" , 0, 0);
    To stop recording sound :
    Code:
    mciSendString("close MyRecorder", "" , 0, 0);
    That's it !

    For complete list of MCI Strings, go here : http://msdn.microsoft.com/en-us/library/ms710815(VS.85,loband).aspx

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

Share This Page