From d7ac4628e33f6fc0d47e04c772408ec8799b6c26 Mon Sep 17 00:00:00 2001 From: Michael Towsey Date: Fri, 21 Jun 2019 15:03:22 +1000 Subject: [PATCH] Begin work on flying fox recogniser Branch for Issue-#238 --- .../Recognizers/PteropusSpecies.cs | 66 +++++++++++-------- src/AnalysisPrograms/Sandpit.cs | 2 +- 2 files changed, 40 insertions(+), 28 deletions(-) diff --git a/src/AnalysisPrograms/Recognizers/PteropusSpecies.cs b/src/AnalysisPrograms/Recognizers/PteropusSpecies.cs index 82e461607..6d8003a47 100644 --- a/src/AnalysisPrograms/Recognizers/PteropusSpecies.cs +++ b/src/AnalysisPrograms/Recognizers/PteropusSpecies.cs @@ -46,7 +46,7 @@ namespace AnalysisPrograms.Recognizers /// internal class PteropusSpecies : RecognizerBase { - public override string Author => "Truskinger"; + public override string Author => "Towsey"; public override string SpeciesName => "PteropusSpecies"; @@ -81,19 +81,28 @@ public override void SummariseResults( /// recogniser results. public override RecognizerResults Recognize(AudioRecording audioRecording, Config configuration, TimeSpan segmentStartOffset, Lazy getSpectralIndexes, DirectoryInfo outputDirectory, int? imageWidth) { - // Get a value from the config file - with a backup default - int minHz = configuration.GetIntOrNull(AnalysisKeys.MinHz) ?? 600; + // get the common properties + string speciesName = configuration[AnalysisKeys.SpeciesName] ?? ""; + string abbreviatedSpeciesName = configuration[AnalysisKeys.AbbreviatedSpeciesName] ?? ""; - // Get a value from the config file - with no default, throw an exception if value is not present - //int maxHz = ((int?)configuration[AnalysisKeys.MaxHz]).Value; + RecognizerResults results = Gruntwork(audioRecording, configuration, outputDirectory, segmentStartOffset); + + return results; + } + /// + /// THis method does the work. + /// + /// the recording. + /// the config file. + /// where results are to be put. + /// where one segment is located in the total recording. + /// a list of events. + internal static RecognizerResults Gruntwork(AudioRecording audioRecording, Config configuration, DirectoryInfo outputDirectory, TimeSpan segmentStartOffset) + { // Get a value from the config file - without a string accessor, as a double double someExampleSettingA = configuration.GetDoubleOrNull("SomeExampleSettingA") ?? 0.0; - // common properties - string speciesName = configuration[AnalysisKeys.SpeciesName] ?? ""; - string abbreviatedSpeciesName = configuration[AnalysisKeys.AbbreviatedSpeciesName] ?? ""; - /* * Examples of using profiles */ @@ -115,6 +124,27 @@ public override RecognizerResults Recognize(AudioRecording audioRecording, Confi //###################### //2.Convert each segment to a spectrogram. + double noiseReductionParameter = configuration.GetDoubleOrNull(AnalysisKeys.NoiseBgThreshold) ?? 0.1; + + // make a spectrogram + var sonoConfig = new SonogramConfig + { + WindowSize = 512, + NoiseReductionType = NoiseReductionType.Standard, + NoiseReductionParameter = configuration.GetDoubleOrNull(AnalysisKeys.NoiseBgThreshold) ?? 0.0, + }; + sonoConfig.WindowOverlap = 0.0; + + // now construct the standard decibel spectrogram WITH noise removal, and look for LimConvex + // get frame parameters for the analysis + var sonogram = (BaseSonogram)new SpectrogramStandard(sonoConfig, audioRecording.WavReader); + + var sonoImage = sonogram.GetImageFullyAnnotated("Test"); + string imageFilename = "Test.png"; + sonoImage.Save(Path.Combine(outputDirectory.FullName, imageFilename)); + + // get samples + var samples = audioRecording.WavReader.Samples; // Profile example: running the same algorithm on every profile with different settings (regional variation) /* @@ -188,27 +218,9 @@ private static List RunFemaleProfile(configuration, rest of argum } */ - // get samples - var samples = audioRecording.WavReader.Samples; - - // make a spectrogram - var config = new SonogramConfig - { - NoiseReductionType = NoiseReductionType.Standard, - NoiseReductionParameter = configuration.GetDoubleOrNull(AnalysisKeys.NoiseBgThreshold) ?? 0.0, - }; - var sonogram = (BaseSonogram)new SpectrogramStandard(config, audioRecording.WavReader); // get high resolution indices - // when the value is accessed, the indices are calculated - var indices = getSpectralIndexes.Value; - - // check if the indices have been calculated - you shouldn't actually need this - if (getSpectralIndexes.IsValueCreated) - { - // then indices have been calculated before - } var foundEvents = new List(); diff --git a/src/AnalysisPrograms/Sandpit.cs b/src/AnalysisPrograms/Sandpit.cs index f4f68d044..595898d00 100644 --- a/src/AnalysisPrograms/Sandpit.cs +++ b/src/AnalysisPrograms/Sandpit.cs @@ -276,7 +276,7 @@ public static void Audio2CsvOverOneFile() //audio2csv "C:\SensorNetworks\WavFiles\KoalaMale\SmallTestSet\DaguilarGoldCreek1_DM420157_0000m_00s__0059m_47s_49h.mp3" "C:\SensorNetworks\Software\AudioAnalysis\AnalysisConfigFiles\Towsey.MultiAnalyser.cfg" "C:\SensorNetworks\Output\Test1" // FLYING FOX RECORDINGS - string recordingPath = @"C:\SensorNetworks\WavFiles\TsheringDema\WBH12HOURS-D_20160403_120000.wav"; + string recordingPath = @"C:\Ecoacoustics\WavFiles\BradLawData\FlyingFox\20190127_Bellingen_Feeding_SM4.wav"; string configPath = @"C:\Work\GitHub\audio-analysis\src\AnalysisConfigFiles\RecognizerConfigFiles\Towsey.PteropusSpecies.yml"; string outputPath = @"C:\Ecoacoustics\Output\BradLaw\FlyingFox";