"Recording a sound" Help

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

  1. pb_ce85

    pb_ce85 New Member

    Joined:
    Jul 13, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Iran
    Hello
    Does anyone knows how can record a sound from an available microphone?
    Thanks
     
  2. SaswatPadhi

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

    Joined:
    May 5, 2009
    Messages:
    1,342
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    http://www.crackingforfun.blogspot.com
    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

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice