コード例 #1
0
        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();
            }
        }
コード例 #2
0
        /// <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";
        }