Ejemplo n.º 1
0
        public void sample_test()
        {
            string basePath = NUnit.Framework.TestContext.CurrentContext.TestDirectory;
            string pathWhereTheDatasetShouldBeStored = Path.Combine(basePath, "mfcc");

            #region doc_example1
            // Let's say we would like to analyse an audio sample. To give an example that
            // could be reproduced by anyone without having to give a specific sound file
            // that would need to have been downloaded by every user trying to run this example,
            // we will use obtain an example from the Free Spoken Digits Dataset instead:
            var fsdd = new FreeSpokenDigitsDataset(path: pathWhereTheDatasetShouldBeStored);

            // Let's obtain one of the audio signals:
            Signal a          = fsdd.GetSignal(0, "jackson", 10);
            int    sampleRate = a.SampleRate; // 8000

            // Note: if you would like to load a signal from the
            // disk, you could use the following method directly:
            // Signal a = Signal.FromFile(fileName);

            // Create a low-pass filter to keep only frequencies below 100 Hz
            var filter = new LowPassFilter(frequency: 100, sampleRate: sampleRate);

            // Apply the filter to the signal
            Signal result = filter.Apply(a);

            // Create a spectrogram for the original
            var sourceSpectrum = new Spectrogram(a);

            // Create a spectrogram for the filtered signal:
            var resultSpectrum = new Spectrogram(result);

            // Get the count for a high frequency before and after the low-pass filter:
            double before = sourceSpectrum.GetFrequencyCount(windowIndex: 0, frequency: 1000); // 0.00028203820434203334
            double after  = resultSpectrum.GetFrequencyCount(windowIndex: 0, frequency: 1000); // 2.9116651158267508E-05
            #endregion

            Assert.AreEqual(0.00028203820434203334, before, 1e-8);
            Assert.AreEqual(2.9116651158267508E-05, after, 1e-8);
        }