コード例 #1
0
        public List <Match> FindAudioFilesContainingSpeaker(Stream speakerAudioFile, string toBeScreenedForAudioFilesWithSpeakerFolder)
        {
            var result = new List <Match>();


            var speakerVoicePrint = VoicePrint.FromFeatures(featureExtractor.ProcessAndExtract(speakerAudioFile));

            foreach (var file in Directory.GetFiles(toBeScreenedForAudioFilesWithSpeakerFolder, "*.wav", SearchOption.TopDirectoryOnly))
            {
                using (var fs = new FileStream(file, FileMode.Open))
                {
                    double[][] words = voiceDetector.SplitBySilence(AudioConverter.ConvertAudioToDoubleArray(fs, sampleRate), sampleRate);

                    int wordsWithinThreshold = 0;
                    for (int i = 0; i < words.Length; i++)
                    {
                        var wordVoicePrint = VoicePrint.FromFeatures(words[i]);

                        double wordDistance = wordVoicePrint.GetDistance(calculator, speakerVoicePrint);
                        if (wordDistance < distanceThreshold)
                        {
                            wordsWithinThreshold++;
                        }
                    }

                    if (words.Length > 0 && (100.0 * ((double)wordsWithinThreshold / words.Length)) > wordsPctThreshold)
                    {
                        var    fVoicePrint = VoicePrint.FromFeatures(featureExtractor.ProcessAndExtract(fs));
                        double fDistance   = fVoicePrint.GetDistance(calculator, speakerVoicePrint);
                        if (fDistance < distanceThreshold)
                        {
                            result.Add(new Match(file, fDistance));
                        }
                    }
                }
            }


            return(result);
        }
コード例 #2
0
        public List <Match> FindAudioFilesContainingSpeaker(Stream speakerAudioFile, string toBeScreenedForAudioFilesWithSpeakerFolder)
        {
            var result = new List <Match>();

            var speakerPrint = VoicePrint.FromFeatures(featureExtractor.ProcessAndExtract(speakerAudioFile));

            foreach (var file in Directory.GetFiles(toBeScreenedForAudioFilesWithSpeakerFolder, "*.wav", SearchOption.TopDirectoryOnly))
            {
                using (var fs = new FileStream(file, FileMode.Open))
                {
                    var vp_test  = VoicePrint.FromFeatures(featureExtractor.ProcessAndExtract(fs));
                    var distance = vp_test.GetDistance(calculator, speakerPrint);

                    if (distance > distanceThreshold)
                    {
                        result.Add(new Match(file, distance));
                    }
                }
            }

            return(result);
        }