The code does not work i am trying to record voice from mic when start button press and output to the spaeaker when user press play button and stop play or record . Implemented in visual studio 2008 using c#
Its not working properly
Loading
Lalit MPosted Feb 18, 2010, 4:31 AM
Raaj KumarPosted Feb 18, 2010, 4:22 AM
Below is the code for what you were looking for. Make sure that you are adding reference to Microsoft.VisualBasic from Add reference window.
using System.Runtime.InteropServices;
using Microsoft.VisualBasic;
using Microsoft.VisualBasic.Devices;
[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);
private void Record()
{
mciSendString("open new Type waveaudio Alias recsound", "", 0, 0);
mciSendString("record recsound", "", 0, 0);
}
private void SaveRecordedSound()
{
mciSendString("save recsound c:\\record.wav", "", 0, 0);
mciSendString("close recsound ", "", 0, 0);
Computer computer = new Computer();
computer.Audio.Stop();
}
private void Play()
{
Computer computer = new Computer();
computer.Audio.Play("c:\\record.wav", AudioPlayMode.Background);
}
Regards,
Raaj