How to record voice from microphone?


using Microsoft.VisualBasic.Devices;
using Microsoft.VisualBasic;
using System.Runtime.InteropServices;

تابع 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 دكمه با نامهاي زير بسازيد :
  • Record
  • SaveStop
  • Read
در زمان كليك شدن دكمه Record بنويسيد :
// record from microphone
mciSendString("open new Type waveaudio Alias recsound", "", 0, 0);
mciSendString("record recsound", "", 0, 0);

و هنگام كليك شدن دكمه SaveStop
// stop and save
mciSendString("save recsound c:\\record.wav", "", 0, 0);
mciSendString("close recsound ", "", 0, 0);
Computer c = new Computer();
c.Audio.Stop();

و براي دكمه Read نيز :
Computer computer = new Computer();
computer.Audio.Play("c:\\record.wav", AudioPlayMode.Background);

منبع :
http://www.dotnetspider.com/resource...icrophone.aspx