private void button2_Click(object sender, EventArgs e) { List <User> s = TestcaseLoader.LoadTestcase1Training(@"E:\programing education\ain shams stage 3\just year\algorithm\labs\PROJECT RELEASE (1)\Startup Codes\Speaker Identification Startup Code\Speaker Identification Startup Code\Complete SpeakerID Dataset\TrainingList.txt"); int sz = s.Count; for (int i = 0; i < sz; i++) { string a = s[i].UserName; int si = s[i].UserTemplates.Count; for (int j = 0; i < si; j++) { Sequence seqq = AudioOperations.ExtractFeatures(s[i].UserTemplates[j]); seq_input = seqq; ////////////// ** save input sequence of audio **///////// FileStream fs = new FileStream("sequence.txt", FileMode.Append); StreamWriter sw = new StreamWriter(fs); int sz_seq = seqq.Frames.Length; sw.Write(sz_seq); sw.Write('%'); sw.WriteLine(a); for (int b = 0; b < sz_seq; b++) { for (int r = 0; r < 13; r++) { sw.WriteLine(seq_input.Frames[b].Features[r]); } } sw.Close(); fs.Close(); ////////////////// ** end save *****///////////////////// } } }
private void btnAdd_Click(object sender, EventArgs e) { if (TestCase1.Checked) { string name = ""; List <User> t = TestcaseLoader.LoadTestcase1Training(@"C:\test\Complete SpeakerID Dataset\TrainingList.txt"); FileStream F = new FileStream("Projectsequences1.txt", FileMode.Append); StreamWriter sa = new StreamWriter(F); for (int i = 0; i < t.Count; i++) { name = t[i].UserName; for (int j = 0; j < t[i].UserTemplates.Count; j++) { AudioSignal sig = new AudioSignal(); seq = AudioOperations.ExtractFeatures(t[i].UserTemplates[j]); record = ""; for (int k = 0; k < seq.Frames.Length; k++) { for (int l = 0; l < 13; l++) { record += seq.Frames[k].Features[l]; if (l != 12) { record += "@"; } } if (k != seq.Frames.Length - 1) { record += "#"; } } sa.WriteLine(name); sa.WriteLine(record); } } sa.Close(); } if (TestCase2.Checked) { string name = ""; List <User> t = TestcaseLoader.LoadTestcase2Training(@"C:\test\Complete SpeakerID Dataset\TrainingList.txt"); FileStream F = new FileStream("Projectsequences2.txt", FileMode.Append); StreamWriter sa = new StreamWriter(F); for (int i = 0; i < t.Count; i++) { name = t[i].UserName; for (int j = 0; j < t[i].UserTemplates.Count; j++) { AudioSignal sig = new AudioSignal(); seq = AudioOperations.ExtractFeatures(t[i].UserTemplates[j]); record = ""; for (int k = 0; k < seq.Frames.Length; k++) { for (int l = 0; l < 13; l++) { record += seq.Frames[k].Features[l]; if (l != 12) { record += "@"; } } if (k != seq.Frames.Length - 1) { record += "#"; } } sa.WriteLine(name); sa.WriteLine(record); } } sa.Close(); } if (TestCase3.Checked) { string name = ""; List <User> t = TestcaseLoader.LoadTestcase3Training(@"C:\test\Complete SpeakerID Dataset\TrainingList.txt"); FileStream F = new FileStream("Projectsequences3.txt", FileMode.Append); StreamWriter sa = new StreamWriter(F); for (int i = 0; i < t.Count; i++) { name = t[i].UserName; for (int j = 0; j < t[i].UserTemplates.Count; j++) { AudioSignal sig = new AudioSignal(); seq = AudioOperations.ExtractFeatures(t[i].UserTemplates[j]); record = ""; for (int k = 0; k < seq.Frames.Length; k++) { for (int l = 0; l < 13; l++) { record += seq.Frames[k].Features[l]; if (l != 12) { record += "@"; } } if (k != seq.Frames.Length - 1) { record += "#"; } } sa.WriteLine(name); sa.WriteLine(record); } } sa.Close(); } if (Normal.Checked) { FileStream F = new FileStream("Projectsequences.txt", FileMode.Append); StreamWriter sa = new StreamWriter(F); Console.WriteLine("enter your name : "); string name = Console.ReadLine(); record = ""; for (int k = 0; k < seq.Frames.Length; k++) { for (int l = 0; l < 13; l++) { record += seq.Frames[k].Features[l]; if (l != 12) { record += "@"; } } if (k != seq.Frames.Length - 1) { record += "#"; } } sa.WriteLine(name); sa.WriteLine(record); sa.Close(); } }
/// <summary> /// Enable the interface objects used to get the speaker's name /// </summary> /// private void btnAdd_Click(object sender, EventArgs e) { /// <summary> /// Disabling Add and Identify buttons /// </summary> /// btnIdentify.Enabled = false; btnAdd.Enabled = false; labelStatus.Text = "Status: Generating sequence and adding to database..."; // To handle 3 testcases List <User>[] Training = new List <User> [3]; Training[0] = TestcaseLoader.LoadTestcase1Training(@"C:\SpeakerID\Test Cases\Complete SpeakerID Dataset\TrainingList.txt"); Training[1] = TestcaseLoader.LoadTestcase2Training(@"C:\SpeakerID\Test Cases\Complete SpeakerID Dataset\TrainingList.txt"); Training[2] = TestcaseLoader.LoadTestcase3Training(@"C:\SpeakerID\Test Cases\Complete SpeakerID Dataset\TrainingList.txt"); for (int kk = 0; kk < 3; kk++) // To loop on all 3 testcases and write the sequences in the database { for (int w = 0; w < Training[kk].Count; w++) // To loop on all users in each testcase { for (int y = 0; y < Training[kk][w].UserTemplates.Count; y++) // To loop on all templates for each user { Sequence seqTemp = AudioOperations.ExtractFeatures(Training[kk][w].UserTemplates[y]); /// <summary> /// Writes the sequence into the Database directory in C: drive -> C:/SpeakerID/Database /// Delimiter between each feature in one frame: % /// Delimiter between frames: # /// </summary> /// { FileStream fs = new FileStream("C:/SpeakerID/case" + (kk + 1) + "/Database/" + Training[kk][w].UserName + y.ToString() + ".txt", FileMode.Create); StreamWriter sw = new StreamWriter(fs); /// <summary> /// For loop: converts a file from type "Sequence" -> seqTemp into a string that's ready to be written to a file /// </summary> /// for (int i = 0; i < seqTemp.Frames.Length; i++) { for (int j = 0; j < 13; j++) { sw.Write(seqTemp.Frames[i].Features[j]); if (j != 12) { sw.Write('%'); } } if (i != seqTemp.Frames.Length - 1) { sw.Write('#'); } } sw.Close(); /// <summary> /// Writes the relationship between speaker's name and the sequence file in the database, in the direcvtory -> C:/SpeakerID/Relathions.txt /// Delimiter between speaker's name and the path: % /// Delimiter between two relations: # /// </summary> /// fs = new FileStream("C:/SpeakerID/case" + (kk + 1) + "/Relations.txt", FileMode.Append); sw = new StreamWriter(fs); sw.Write(Training[kk][w].UserName + '%' + "C:/SpeakerID/case" + (kk + 1) + "/Database/" + Training[kk][w].UserName + y.ToString() + ".txt" + '#'); sw.Close(); } } } } labelStatus.Text = "Status: Ready"; }
private void button3_Click(object sender, EventArgs e) { List <User> s = TestcaseLoader.LoadTestcase1Training(@"E:\programing education\ain shams stage 3\just year\algorithm\labs\PROJECT RELEASE (1)\Startup Codes\Speaker Identification Startup Code\Speaker Identification Startup Code\Complete SpeakerID Dataset\TestingList.txt"); int sz = s.Count; //string[] list_name =new string [s]; for (int i = 0; i < sz; i++) { string a = s[i].UserName; int si = s[i].UserTemplates.Count; for (int j = 0; i < si; j++) { Sequence seqq = AudioOperations.ExtractFeatures(s[i].UserTemplates[j]); sz_input = seqq.Frames.Length; seq_input = seqq; FileStream fs = new FileStream("sequence.txt", FileMode.Open); StreamReader sr = new StreamReader(fs); double match = double.PositiveInfinity; string name = ""; while (sr.Peek() != -1) { string line = sr.ReadLine(); string[] fields = line.Split('%'); int sz_out = int.Parse(fields[0]); string name_out = fields[1]; seq_out = new double[sz_out, 13]; ////////**read feature from file ****//////// for (int u = 0; u < sz_out; u++) { for (int y = 0; y < 13; y++) { seq_out[u, y] = double.Parse(sr.ReadLine()); } } ////////** save values in seq_out and find cost **/////* /////////////* DTW**///////////////////////////////////////// ////////////**DTW***//////////////////////////////////////// int w = Math.Abs(sz_input - sz_out); // adapt window size (*) double[] D = new double[sz_input + 1]; for (int u = 0; u <= sz_input; u++) { D[u] = double.PositiveInfinity; } for (int u = 1; u <= sz_out; u++) { ///////////// { if (u - 1 == 0) { D[0] = 0; } else { D[0] = double.PositiveInfinity; } int a2 = 0, a3 = 1; double A1 = D[0], A2 = D[a2], A3 = D[a3]; /////////////////// for (int y = Math.Max(1, u - w); y <= Math.Min(sz_input, u + w); y++) { //////////////////// double cost = 0; for (int f = 0; f < 13; f++) { cost += Math.Pow(seq_input.Frames[y - 1].Features[f] - seq_out[u - 1, f], 2); } cost = Math.Sqrt(cost); double c = 0; if (A1 == 0.0) { c = cost + Math.Min(A1, A2); } else { c = cost + Math.Min(A1, Math.Min(A2, A3)); } ////////////////////// if (a3 < sz_input) { a3++; a2++; A1 = A2; A2 = D[a2]; A3 = D[a3]; } D[y] = c; } } if (match > D[sz_input]) { match = D[sz_input]; name = name_out; } } } //////////////////////////*****end file****/////////////////////////////////////////// sr.Close(); fs.Close(); //////// set list of string list_us.Insert(i * j, name); //////// } } for (int i = 0; i < list_us.Count; i++) { Console.Write(list_us[i]); } Console.WriteLine(); }