Esempio n. 1
0
        /**
         * Creates a voice print and stores it along with the user key for later comparison with new samples
         * <p>
         * Threading : this method is synchronized to prevent inadvertently erasing an existing user key
         * </p>
         * @param userKey the user key associated with this voice print
         * @param voiceSample the voice sample, values between -1.0 and 1.0
         * @return the voice print extracted from the given sample
         */
        public VoicePrint CreateVoicePrint(T userKey, double[] voiceSample)
        {
            lock (_lock)
            {
                if (userKey == null)
                {
                    throw new ArgumentNullException(nameof(userKey), "The userKey is null");
                }

                if (store.ContainsKey(userKey))
                {
                    throw new ArgumentException("The userKey already exists: [{userKey}");
                }

                double[]   features   = audioProcessor.ProcessAndExtract(voiceSample);
                VoicePrint voicePrint = new VoicePrint(features);

                if (!universalModelWasSetByUser)
                {
                    if (universalModel == null)
                    {
                        universalModel = new VoicePrint(voicePrint);
                    }
                    else
                    {
                        universalModel.Merge(features);
                    }
                }

                store.Add(userKey, voicePrint);

                return(voicePrint);
            }
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }