Click here to Skip to main content
15,920,708 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi
i've found a code that records voice from Microphone:
1. Open C#.net web applications. And added the blow namespace. using
Microsoft.VisualBasic.Devices; using Microsoft.VisualBasic; using System.Runtime.InteropServices; 

2. Add the below API.
[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); 

3. Create three Buttons and given the below name and text for the buttons. 1. Record 2. SaveStop 3. Read
1. Under Record Button Click paste the below Code:
// record from microphone 
mciSendString("open new Type waveaudio Alias recsound", "", 0, 0); mciSendString("record recsound", "", 0, 0); 

2. Under Save / Stop button Click, // stop and save
mciSendString("save recsound c:\record.wav", "", 0, 0); mciSendString("close recsound ", "", 0, 0); Computer c = new Computer(); c.Audio.Stop(); 

3. Under Read Button Click
Computer computer = new Computer(); computer.Audio.Play("c:\record.wav", AudioPlayMode.Background); 
Save and Execute it.

my problem is that i dont know how to add sound card's APIs & usings to my project;when i add lines directly to code , there are some errors; i think i should add them in some where else too i'd be so glad if anyone help me
Posted
Updated 9-Aug-10 0:19am
v3

1 solution

mciSendString sends commands to a multimedia device. Windows will map those commands to the device's drivers for you, so you needn't really worry about what happens in the middle. There are no "usings" required, only the DLLImport as you have it.

Doco for mciSendString on MSDN is at http://msdn.microsoft.com/en-us/library/dd757161(VS.85).aspx[^]

The first parameter is a command. List of commands and their functionality and parameters is at http://msdn.microsoft.com/en-us/library/dd743572(VS.85).aspx[^].

If you get errors it may help to call mciGetErrorString (which translates the error code to a readable message) or see the list of possible return values at http://msdn.microsoft.com/en-us/library/dd757153(VS.85).aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900