/// <summary> /// Find the narest voice with the same password told in the voice file /// </summary> /// <param name="waveFileName">the path to input wave file</param> /// <returns></returns> public VoiceIdentity Identify(string waveFileName) { // obtain the password candidates told in the input voice HashSet <string> passwords = new HashSet <string>(speechRecognizer.SpeechToText(waveFileName)); // initially set the result to null VoiceIdentity nearest = null; // find the identity with the same password and least distance meeting the threshold double leastDistance = Double.MaxValue; foreach (VoiceIdentity identity in identities.Values) { if (!passwords.Contains(identity.Password)) { continue; } // calculate input file distance from the identity double distance = identity.Distance(waveFileName); // if it is more than threshold go to next identity if (distance > threhold) { continue; } if (distance < leastDistance) { nearest = identity; leastDistance = distance; } } return(nearest); }