Esta clase nos ayuda a capturar un WAv desde C# de forma sencilla
class Audio2
{
[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);
Boolean recording = false;
public String Iniciar()
{
try
{
if (!recording)
{
mciSendString("open new Type waveaudio Alias recsound", "", 0, 0);
mciSendString("record recsound", "", 0, 0);
recording = true;
return "OK";
}
else
{
return "Ya se esta grabando";
}
}
catch (Exception ex)
{
//recording = false;
return ex.Message;
}
}
public String Stop(String _file)
{
try
{
if (recording)
{
mciSendString(@"save recsound " + _file, "", 0, 0);
mciSendString("close recsound ", "", 0, 0);
recording = true;
return "OK";
}
else
{
return "No se esta grabando";
}
}
catch (Exception ex)
{
return ex.Message;
}
}
public byte[] Stop(String _file)
{
try
{
if (recording)
{
mciSendString(@"save recsound " + _file, "", 0, 0);
mciSendString("close recsound ", "", 0, 0);
byte[] bytes = File.ReadAllBytes(_file);
recording = false;
return bytes;
}
else
{
throw new Exception("No se esta grabando");
}
}
catch (Exception ex)
{
throw ex;
}
}
}
No hay comentarios:
Publicar un comentario