Example #1
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            labelStatus.Text = "Status: Opening audio file...";
            OpenFileDialog open = new OpenFileDialog();

            if (open.ShowDialog() == DialogResult.OK)
            {
                isRecorded = false;
                path       = open.FileName;
                //Open the selected audio file
                signal = AudioOperations.OpenAudioFile(path);
                Sequence seq = AudioOperations.ExtractFeatures(signal);
                updateButtons();

                /// Enabling buttons Add and Identify
                /// The buttons btnIdentify and btnAdd are enabled ONLY after opening
                /// audio file
                ///
            }
            /// <summary>
            ///  Updating status label
            /// </summary>
            ///
            labelStatus.Text = "Status: Ready";
        }
Example #2
0
        //========================================================================================================================================//

        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            saveFileDialog1.ShowDialog(this);
            string name = saveFileDialog1.FileName;

            signal = AudioOperations.OpenAudioFile(name);
            //  Rsignal = AudioOperations.RemoveSilence(signal);

            Sequence sequ = AudioOperations.ExtractFeatures(signal);
        }
Example #3
0
        //========================================================================================================================================//

        private void btnAdd_Click(object sender, EventArgs e)
        {
            saveFileDialog1.ShowDialog(this);
            string name = saveFileDialog1.FileName;

            signal = AudioOperations.OpenAudioFile(name);
            //  Rsignal = AudioOperations.RemoveSilence(signal);

            Sequence sequ = AudioOperations.ExtractFeatures(signal);

            RWFile wr = new RWFile();

            wr.WriteTestFile(sequ);
        }
Example #4
0
        //========================================================================================================================================//
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog open = new OpenFileDialog();

            if (open.ShowDialog() == DialogResult.OK)
            {
                isRecorded = false;
                path       = open.FileName;
                //Open the selected audio file
                signal = AudioOperations.OpenAudioFile(path);

                Sequence seq = AudioOperations.ExtractFeatures(signal);
                updateButtons();
            }
        }
Example #5
0
        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  *****/////////////////////
                }
            }
        }
Example #6
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog open = new OpenFileDialog();

            if (open.ShowDialog() == DialogResult.OK)
            {
                isRecorded = false;
                path       = open.FileName;
                //Open the selected audio file
                signal = AudioOperations.OpenAudioFile(path);

                // remove sielnce
                AudioOperations.RemoveSilence(signal);

                Sequence seq = AudioOperations.ExtractFeatures(signal);

                seq_input = seq; /////*** seq_input initialize by open audio/////////
                sz_input  = seq_input.Frames.Length;

                textBox2.Text = "";
                textBox3.Text = "";
                updateButtons();
            }
        }
Example #7
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (TestCase1.Checked)
            {
                List <User> t    = TestcaseLoader.LoadTestcase1Testing(@"C:\test\Complete SpeakerID Dataset\TestingList.txt");
                Stopwatch   time = new Stopwatch();

                FileStream   f = new FileStream("Projectsequences1.txt", FileMode.Open);
                StreamReader s = new StreamReader(f);
                //Random rd = new Random();

                seq = AudioOperations.ExtractFeatures(t[0].UserTemplates[0]);
                double min2 = double.MaxValue;
                string ans2 = "";
                //Console.Write("Enter The Window Index :");
                // int w = Console.Read();
                while (s.Peek() != -1)
                {
                    double res2     = 0;
                    string sequence = "";
                    string _name    = s.ReadLine();
                    sequence = s.ReadLine();
                    string[] arr  = sequence.Split('#');
                    string[] arr3 = new string[arr.Length];
                    Sequence seq2 = new Sequence();
                    seq2.Frames = new MFCCFrame[arr.Length];
                    for (int i = 0; i < arr.Length; i++)
                    {
                        seq2.Frames[i] = new MFCCFrame();
                        for (int o = 0; o < arr.Length; o++)
                        {
                            arr3 = arr[o].Split('@');
                        }
                        for (int j = 0; j < 13; j++)
                        {
                            seq2.Frames[i].Features[j] = double.Parse(arr3[j]);
                        }
                    }
                    time.Start();
                    res2 = PRUNINGDTW.DTW2fun(seq, seq2);
                    time.Stop();
                    if (res2 < min2)
                    {
                        min2 = res2;
                        ans2 = _name;
                    }
                }
                Console.WriteLine("NEW DTW");
                Console.WriteLine(ans2 + " " + min2);

                Console.WriteLine("Time elapsed: {0:hh\\:mm\\:ss}", time.Elapsed);
                s.Close();
            }

            if (TestCase2.Checked)
            {
                List <User> t    = TestcaseLoader.LoadTestcase2Testing(@"C:\test\Complete SpeakerID Dataset\TestingList.txt");
                Stopwatch   time = new Stopwatch();

                FileStream   f = new FileStream("Projectsequences2.txt", FileMode.Open);
                StreamReader s = new StreamReader(f);

                seq = AudioOperations.ExtractFeatures(t[0].UserTemplates[0]);
                double min2 = double.MaxValue;
                string ans2 = "";
                //Console.Write("Enter The Window Index :");
                // int w = Console.Read();
                while (s.Peek() != -1)
                {
                    double res2     = 0;
                    string sequence = "";
                    string _name    = s.ReadLine();
                    sequence = s.ReadLine();
                    string[] arr  = sequence.Split('#');
                    string[] arr3 = new string[arr.Length];
                    Sequence seq2 = new Sequence();
                    seq2.Frames = new MFCCFrame[arr.Length];
                    for (int i = 0; i < arr.Length; i++)
                    {
                        seq2.Frames[i] = new MFCCFrame();
                        for (int o = 0; o < arr.Length; o++)
                        {
                            arr3 = arr[o].Split('@');
                        }
                        for (int j = 0; j < 13; j++)
                        {
                            seq2.Frames[i].Features[j] = double.Parse(arr3[j]);
                        }
                    }
                    time.Start();
                    res2 = PRUNINGDTW.DTW2fun(seq, seq2);
                    time.Stop();
                    if (res2 < min2)
                    {
                        min2 = res2;
                        ans2 = _name;
                    }
                }
                Console.WriteLine("NEW DTW");
                Console.WriteLine(ans2 + " " + min2);

                Console.WriteLine("Time elapsed: {0:hh\\:mm\\:ss}", time.Elapsed);
                s.Close();
            }

            if (TestCase3.Checked)
            {
                List <User> t    = TestcaseLoader.LoadTestcase3Testing(@"C:\test\Complete SpeakerID Dataset\TestingList.txt");
                Stopwatch   time = new Stopwatch();
                for (int k = 0; k < t.Count; k++)
                {
                    FileStream   f       = new FileStream("Projectsequences3.txt", FileMode.Open);
                    StreamReader s       = new StreamReader(f);
                    Random       rd      = new Random();
                    int          counter = rd.Next(0, t[k].UserTemplates.Count);
                    seq = AudioOperations.ExtractFeatures(t[k].UserTemplates[counter]);
                    double min2 = double.MaxValue;
                    string ans2 = "";
                    //Console.Write("Enter The Window Index :");
                    // int w = Console.Read();
                    while (s.Peek() != -1)
                    {
                        double res2     = 0;
                        string sequence = "";
                        string _name    = s.ReadLine();
                        sequence = s.ReadLine();
                        string[] arr  = sequence.Split('#');
                        string[] arr3 = new string[arr.Length];
                        Sequence seq2 = new Sequence();
                        seq2.Frames = new MFCCFrame[arr.Length];
                        for (int i = 0; i < arr.Length; i++)
                        {
                            seq2.Frames[i] = new MFCCFrame();
                            for (int o = 0; o < arr.Length; o++)
                            {
                                arr3 = arr[o].Split('@');
                            }
                            for (int j = 0; j < 13; j++)
                            {
                                seq2.Frames[i].Features[j] = double.Parse(arr3[j]);
                            }
                        }
                        time.Start();
                        res2 = PRUNINGDTW.DTW2fun(seq, seq2);
                        if (res2 < min2)
                        {
                            min2 = res2;
                            ans2 = _name;
                        }
                        Console.WriteLine("NEW DTW");
                        Console.WriteLine(ans2 + " " + min2);
                        time.Stop();
                        Console.WriteLine("Time elapsed: {0:hh\\:mm\\:ss}", time.Elapsed);
                    }
                    Console.WriteLine(ans2);
                    Console.WriteLine(min2);
                    MessageBox.Show(ans2 + " " + min2);
                    s.Close();
                }
            }

            if (Normal.Checked)
            {
                FileStream   f    = new FileStream("Projectsequences.txt", FileMode.Open);
                StreamReader s    = new StreamReader(f);
                Stopwatch    time = new Stopwatch();
                double       min2 = double.MaxValue;
                string       ans2 = "";
                //Console.Write("Enter The Window Index :");
                // int w = Console.Read();
                while (s.Peek() != -1)
                {
                    double res2     = 0;
                    string sequence = "";
                    string _name    = s.ReadLine();
                    sequence = s.ReadLine();
                    string[] arr  = sequence.Split('#');
                    string[] arr3 = new string[arr.Length];
                    Sequence seq2 = new Sequence();
                    seq2.Frames = new MFCCFrame[arr.Length];
                    for (int i = 0; i < arr.Length; i++)
                    {
                        seq2.Frames[i] = new MFCCFrame();
                        for (int o = 0; o < arr.Length; o++)
                        {
                            arr3 = arr[o].Split('@');
                        }
                        for (int j = 0; j < 13; j++)
                        {
                            seq2.Frames[i].Features[j] = double.Parse(arr3[j]);
                        }
                    }
                    time.Start();
                    res2 = PRUNINGDTW.DTW2fun(seq, seq2);
                    if (res2 < min2)
                    {
                        min2 = res2;
                        ans2 = _name;
                    }
                    Console.WriteLine("NEW DTW");
                    Console.WriteLine(ans2 + " " + min2);
                    time.Stop();
                    Console.WriteLine("Time elapsed: {0:hh\\:mm\\:ss}", time.Elapsed);
                }
                Console.WriteLine(ans2);
                Console.WriteLine(min2);
                s.Close();
            }
        }
Example #8
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();
            }
        }
Example #9
0
        private void btnIdentify_Click(object sender, EventArgs e)
        {
            /// <summary>
            /// updating status label
            /// </summary>
            ///
            metroLabel1.Visible    = true;
            pruningToggle1.Visible = true;
            labelStatus.Text       = "Status: Identifying speaker and running DTW algorithm...";


            List <User> test = new List <User>();
            string      cnt  = "";// To choose a testcase

            if (Testcase1_radioButton.Checked == true)
            {
                test = TestcaseLoader.LoadTestcase1Testing(@"C:\SpeakerID\Test Cases\Complete SpeakerID Dataset\TestingList.txt"); cnt = "1";
            }
            else if (Testcase2_radioButton.Checked == true)
            {
                test = TestcaseLoader.LoadTestcase2Testing(@"C:\SpeakerID\Test Cases\Complete SpeakerID Dataset\TestingList.txt"); cnt = "2";
            }
            else if (Testcase3_radioButton.Checked == true)
            {
                test = TestcaseLoader.LoadTestcase3Testing(@"C:\SpeakerID\Test Cases\Complete SpeakerID Dataset\TestingList.txt"); cnt = "3";
            }
            else if (caseMilestone1.Checked) //First testcase
            {
                AudioSignal signalTemp = AudioOperations.OpenAudioFile("C:\\SpeakerID\\Test Cases\\Sample Test\\Input sample\\ItIsPlausible_Rich_US_English.wav");
                signalTemp = AudioOperations.RemoveSilence(signalTemp); //don't analyze (template function)
                User userTemp = new User();
                userTemp.UserTemplates = new List <AudioSignal>();
                userTemp.UserName      = ("Rich");
                userTemp.UserTemplates.Add(signalTemp);
                test.Add(userTemp);
                cnt = "4";
            }
            else if (caseMilestone2.Checked)
            {
                AudioSignal signalTemp = AudioOperations.OpenAudioFile("C:\\SpeakerID\\Test Cases\\Pruning Test\\1 min\\[Input] Why Study Algorithms - (1 min).wav");
                signalTemp = AudioOperations.RemoveSilence(signalTemp);
                User userTemp = new User();
                userTemp.UserTemplates = new List <AudioSignal>();
                userTemp.UserName      = ("BigOh (1 min)");
                userTemp.UserTemplates.Add(signalTemp);
                test.Add(userTemp);
                cnt = "5";
            }
            else if (caseMilestone3.Checked)
            {
                AudioSignal signalTemp = AudioOperations.OpenAudioFile("C:\\SpeakerID\\Test Cases\\Pruning Test\\4 min\\[Input] Why Study Algorithms - (4 min).wav");
                signalTemp = AudioOperations.RemoveSilence(signalTemp);
                User userTemp = new User();
                userTemp.UserTemplates = new List <AudioSignal>();
                userTemp.UserName      = ("BigOh (4 min)");
                userTemp.UserTemplates.Add(signalTemp);
                test.Add(userTemp);
                cnt = "6";
            }
            for (int y = 0; y < test.Count; ++y)
            {
                Random      rnd = new Random(); //Generate random number to choose an audio sample to test it against the database
                AudioSignal sig = new AudioSignal();
                sig = test[y].UserTemplates[0]; //rnd.Next(0, test[y].UserTemplates.Count)];
                Sequence compareSequence_input = new Sequence();
                compareSequence_input = AudioOperations.ExtractFeatures(sig);
                FileStream   FS        = new FileStream("C:/SpeakerID/case" + cnt + "/Relations.txt", FileMode.Open);
                StreamReader SR        = new StreamReader(FS);
                string       relations = SR.ReadLine();
                SR.Close();
                /// <summary>
                ///  Split the string relations into an array of strings
                ///   Delimiter: #
                ///  Then split each string into name and path
                ///   Delimiter: %
                ///   Filling an array of "relationItem"s with the names and sequence paths of all sequences in the database, and leaving the
                ///   distance attribute in all the array items as they are "NULL", until calculated using the DTW algorithm
                /// </summary>
                ///
                string[]       relationsStrArr    = relations.Split('#');
                relationItem[] relationsStructArr = new relationItem[relationsStrArr.Length - 1];
                matchedPerson  person             = new matchedPerson();
                person.distance = -1;

                for (int i = 0; i < relationsStructArr.Length; i++)
                {
                    string[] stringArrTemp = relationsStrArr[i].Split('%');
                    relationsStructArr[i].nameStr      = stringArrTemp[0];
                    relationsStructArr[i].sequencePath = stringArrTemp[1];
                }
                Stopwatch sw;
                TimeSpan  TS = TimeSpan.Zero;
                for (int i = 0; i < relationsStructArr.Length; i++) //Loops on all sequences in DB
                {
                    /// Reset the "compareSequence_output" variable and prepare SR for reading the sequence
                    Sequence compareSequence_output = new Sequence();
                    FS = new FileStream(relationsStructArr[i].sequencePath, FileMode.Open);
                    SR = new StreamReader(FS);
                    /// Resetting the "file" variable
                    string file = "";
                    file += SR.ReadLine();
                    string[] strTempFrames = file.Split('#');                            //strTemp now contains all Frames in a sequence
                    compareSequence_output.Frames = new MFCCFrame[strTempFrames.Length]; //Setting number of frames in output sequence
                    for (int j = 0; j < strTempFrames.Length; j++)                       //Loops on all frames in a sequence
                    {
                        string[]  strTempFeatures = strTempFrames[j].Split('%');
                        MFCCFrame frame           = new MFCCFrame();
                        for (int k = 0; k < 13; k++)
                        {
                            frame.Features[k] = double.Parse(strTempFeatures[k]);                          //Loops on all 13 features in a frame and converts string to double
                        }
                        compareSequence_output.Frames[j] = new MFCCFrame();
                        for (int k = 0; k < 13; k++)
                        {
                            compareSequence_output.Frames[j].Features[k] = frame.Features[k];
                        }
                    }

                    /// Save the difference between compareSequence_output and compareSequence_input in relationsStructArr[i].distance
                    if (pruningToggle1.Checked == true)
                    {
                        sw = Stopwatch.StartNew();
                        relationsStructArr[i].distance = Pruning_DTW(compareSequence_input, compareSequence_output);
                        sw.Stop();
                        TS += sw.Elapsed;
                    }
                    else
                    {
                        sw = Stopwatch.StartNew();
                        relationsStructArr[i].distance = DTW_improved(compareSequence_input, compareSequence_output);
                        sw.Stop();
                        TS += sw.Elapsed;
                    }

                    // update person object
                    if (relationsStructArr[i].distance < person.distance || person.distance == -1)
                    {
                        person.distance = relationsStructArr[i].distance;
                        person.name     = relationsStructArr[i].nameStr;
                    }
                    /// Close the SR
                    SR.Close();
                    Console.WriteLine(relationsStructArr[i].nameStr);
                }

                /// <summary>
                ///  Updating status label and showing search results
                /// </summary>
                ///
                labelStatus.Text = "Status: Searching done.";
                Console.WriteLine(test[y].UserName);
                MessageBox.Show("Search completed\nThe closest match to this speaker is: " + person.name + "\nTime Elapsed for DTW only: " + TS.Hours + ':' + TS.Minutes + ':' + TS.Seconds + ':' + TS.Milliseconds + "\nTotal cost: " + person.distance, "Search Results");
                labelStatus.Text = "Status: Ready";
            }
        }
Example #10
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";
        }
Example #11
0
        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();
        }