예제 #1
0
        public MatchResult <string> RecognizeSpeaker(byte[] sample)
        {
            var voiceDetector = new AutocorrellatedVoiceActivityDetector();

            var fullFileName = Path.Combine(_baseDirectory, "identify.wav");

            File.WriteAllBytes(fullFileName, sample);

            foreach (var persons in Directory.GetDirectories(_baseDirectory).OrderBy(f => f))
            {
                var info = new DirectoryInfo(persons);
                var name = info.Name;

                VoicePrint voice = null;

                foreach (var audio in Directory.GetFiles(persons, "*.wav", SearchOption.TopDirectoryOnly))
                {
                    using (var fs = File.OpenRead(audio))
                    {
                        if (voice == null)
                        {
                            voice = recognition.CreateVoicePrint(name, fs);
                        }
                        else
                        {
                            voice = recognition.MergeVoiceSample(name, fs);
                        }
                    }
                }
            }

            MatchResult <string> identify;


            using (var stream = new FileStream(fullFileName, FileMode.Open))
            {
                identify = recognition.Identify(stream).FirstOrDefault();
            }

            File.Delete(fullFileName);

            return(identify);
        }
예제 #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);
        }
예제 #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);
        }
예제 #4
0
        static void Main(string[] args)
        {
            var start = DateTime.Now;

            try
            {
                string base_dir = "C:\\Users\\fabio\\Desktop\\audio_sample";

                var tests = new List <string>();

                using (var waveOut = new WaveOutEvent())
                {
                    var voiceDetector = new AutocorrellatedVoiceActivityDetector();


                    foreach (var pessoas in Directory.GetDirectories(base_dir).OrderBy(f => f))
                    {
                        var info = new DirectoryInfo(pessoas);
                        var nome = info.Name;

                        Console.WriteLine($"nome:{nome}");

                        VoicePrint voice = null;

                        foreach (var audio in Directory.GetFiles(pessoas, "audio_*.wav", SearchOption.TopDirectoryOnly))
                        {
                            Console.WriteLine($"nome:{audio}");



                            using (var fs = File.OpenRead(audio))
                            {
                                if (voice == null)
                                {
                                    voice = recognito.CreateVoicePrint(nome, fs);
                                }
                                else
                                {
                                    voice = recognito.MergeVoiceSample(nome, fs);
                                }
                            }

                            using (var wr = new WaveFileReader(audio))
                            {
                                Console.WriteLine("Play Original");
                                waveOut.Init(wr);
                                waveOut.PlayAndWait();
                            }

                            using (var fs = new FileStream(audio, FileMode.Open))
                            {
                                var sentence = AudioConverter.ConvertAudioToDoubleArray(fs, sampleRate);

                                var words = voiceDetector.SplitBySilence(sentence, sampleRate);

                                var aa = AudioConverter.WriteAudioInputStream(sentence);



                                if (words.Length > 1)
                                {
                                    foreach (var word in words)
                                    {
                                        var aw = AudioConverter.WriteAudioInputStream(word);

                                        using (var wr = new WaveFileReader(aw))
                                        {
                                            Console.WriteLine("Play Word");
                                            waveOut.Init(wr);
                                            waveOut.PlayAndWait();
                                            Thread.Sleep(1000);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                Console.WriteLine("\n\nTestes");
                tests = Directory.GetFiles(base_dir, "teste_*.wav", SearchOption.AllDirectories).ToList();

                foreach (var test in tests)
                {
                    Console.WriteLine($"Testando: {test}");

                    using (var fs = new FileStream(test, FileMode.Open))
                    {
                        var identify = recognito.Identify(fs).FirstOrDefault();

                        Console.WriteLine($"identify.Key:{identify.Key},identify.Distance: {identify.Distance}, identify.LikelihoodRatio:{identify.LikelihoodRatio}");
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("[ERROR]");
                Console.WriteLine(ex);
            }
            finally
            {
                Console.WriteLine($"Time:{(DateTime.Now - start)}");

                Console.WriteLine("Press Any Key do Close");
                Console.ReadKey();
            }
        }
예제 #5
0
        static void Main(string[] args)
        {
            var start = DateTime.Now;

            string base_dir = "D:\\samples";

            var tests = new List <string>();

            using (var waveOut = new WaveOutEvent())
            {
                var voiceDetector = new AutocorrellatedVoiceActivityDetector();


                foreach (var pessoas in Directory.GetDirectories(base_dir).OrderBy(f => f))
                {
                    var info = new DirectoryInfo(pessoas);
                    var nome = info.Name;

                    Console.WriteLine($"nome:{nome}");

                    VoicePrint voice = null;

                    foreach (var audio in Directory.GetFiles(pessoas, "audio_*.wav", SearchOption.TopDirectoryOnly))
                    {
                        Console.WriteLine($"nome:{audio}");



                        using (var fs = File.OpenRead(audio))
                        {
                            if (voice == null)
                            {
                                voice = recognito.CreateVoicePrint(nome, fs);
                            }
                            else
                            {
                                voice = recognito.MergeVoiceSample(nome, fs);
                            }
                        }

                        //using (var wr = new WaveFileReader(audio))
                        //{
                        //	Console.WriteLine("Play Original");
                        //	waveOut.Init(wr);
                        //	waveOut.PlayAndWait();
                        //}
                    }
                }
            }

            Console.WriteLine("\n\nTestes");
            tests = Directory.GetFiles(base_dir, "teste_*.wav", SearchOption.AllDirectories).ToList();

            foreach (var test in tests)
            {
                Console.WriteLine($"Testando: {test}");

                using (var fs = new FileStream(test, FileMode.Open))
                {
                    var identify = recognito.Identify(fs).FirstOrDefault();

                    Console.WriteLine($"identify.Key:{identify.Key},identify.Distance: {identify.Distance}, identify.LikelihoodRatio:{identify.LikelihoodRatio}");
                }
            }


            Console.WriteLine($"Time:{(DateTime.Now - start)}");

            Console.WriteLine("Press Any Key do Close");
            Console.ReadKey();
        }