static private List <User> LoadDataset(string datasetFileName)
        {
            //Get The dataset folder path.
            var    splittedPath = datasetFileName.Split('\\');
            string folderPath   = "";

            for (int i = 0; i < splittedPath.Length - 1; i++)
            {
                folderPath += splittedPath[i] + '\\';
            }
            folderPath += "audiofiles\\";


            //read the training samples files names
            Dictionary <string, User> users = new Dictionary <string, User>();
            StreamReader reader             = new StreamReader(datasetFileName);
            string       line;

            while ((line = reader.ReadLine()) != null)
            {
                string userName = line.Split('/')[0];
                string fileName = line.Split('/')[1] + ".wav";
                //check if user already exists, if not add an entry in the dictionary.
                if (users.ContainsKey(userName) == false)
                {
                    User user = new User();
                    user.UserTemplates = new List <AudioSignal>();
                    user.UserName      = userName;
                    users.Add(userName, user);
                }
                AudioSignal audio;
                string      fullFileName = folderPath + userName + '\\' + fileName;
                try
                {
                    audio = openNISTWav(fullFileName);
                }
                catch (Exception)
                {
                    audio = AudioOperations.OpenAudioFile(folderPath + userName + '\\' + fileName);
                }
                audio = AudioOperations.RemoveSilence(audio);
                users[userName].UserTemplates.Add(audio);
            }
            reader.Close();

            //move the users to a list for convenience reasons only.
            List <User> usersList = new List <User>();

            foreach (var user in users)
            {
                usersList.Add(user.Value);
            }

            return(usersList);
        }
Beispiel #2
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();
            }
        }
Beispiel #3
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";
            }
        }