Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

activex

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 :)

like image 933
Muhammad Adnan Avatar asked May 08 '09 04:05

Muhammad Adnan


2 Answers

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.

like image 119
Jeff Youel Avatar answered Sep 27 '22 22:09

Jeff Youel


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);
like image 29
3 revs, 2 users 65% Avatar answered Sep 27 '22 21:09

3 revs, 2 users 65%