voice record (winmm.dll) using C#.net

18,680

Solution 1

I would use DirectShow to capture the audio. Since you added a C# tag to the question, I recommend using the DirectShow.NET library. Make sure you also download the samples and look at the PlayCap and CapWMV samples in the Capture folder. You may also want to checkout the Audio Capture article at CodeProject.

As for why some OS versions are working, have you confirmed on those systems that the audio input works with other programs? Are you allowing the user to select an audio device or just using the default audio device? Are you getting an error message or just not audio? Per this forum, make sure you wrap your filename in double quotes.

Solution 2

Actually no error, no exception and not even output wav files i am creating, whereas it works fine on vista and 2k8 but not prior versions.

m using default sound card not setting any explicitly

using following code

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

to record

mciSendString("open new Type waveaudio Alias recsound", "", 0, 0);
mciSendString("record recsound", "", 0, 0);

to stop and save

mciSendString(@"save recsound " + OuputFolderName + FileName + ".wav", "", 0, 0);
mciSendString("close recsound ", "", 0, 0);
Share:
18,680
Muhammad Adnan
Author by

Muhammad Adnan

Updated on June 04, 2022

Comments

  • Muhammad Adnan
    Muhammad Adnan almost 2 years

    My requirement was to build an utility which could record voice (through mic) and save on disk .wav files as desktop and web app. for specific users so i chose activeX technology as i didn't find any other better way (may be you know and can guide me.. would be more than welcome)

    I used winmm.dll (aka Media control interface (MCI)) and it is working perfectly fine but on specific computers like when i run it on vista, it works fine and on win server 2008 but on windows 2003 and xp it's not working .. just working is there any prereq.. which needs to be there or what i should do to make it work on other flavors of windows.

    I don't mind in using DirectSound if some1 recommends with some sample code to record/save/play sample :)