コード例 #1
0
ファイル: AED.cs プロジェクト: Gwae1/audio-analysis
        public static Tuple <EventCommon[], AudioRecording, BaseSonogram> Detect(
            FileInfo audioFile,
            AedConfiguration aedConfiguration,
            TimeSpan segmentStartOffset)
        {
            if (aedConfiguration.NoiseReductionType != NoiseReductionType.None && aedConfiguration.NoiseReductionParameter == null)
            {
                throw new ArgumentException("A noise production parameter should be supplied if not using AED noise removal", "noiseReductionParameter");
            }

            var recording       = new AudioRecording(audioFile);
            var segmentDuration = recording.Duration;

            if (recording.SampleRate != aedConfiguration.ResampleRate)
            {
                throw new ArgumentException(
                          "Sample rate of recording ({0}) does not match the desired sample rate ({1})".Format2(
                              recording.SampleRate,
                              aedConfiguration.ResampleRate));
            }

            var config = new SonogramConfig
            {
                NoiseReductionType      = aedConfiguration.NoiseReductionType,
                NoiseReductionParameter = aedConfiguration.NoiseReductionParameter,
            };
            var sonogram = (BaseSonogram) new SpectrogramStandard(config, recording.WavReader);

            var events = CallAed(sonogram, aedConfiguration, segmentStartOffset, segmentDuration);

            Log.Debug("AED # events: " + events.Length);
            return(Tuple.Create(events, recording, sonogram));
        }
コード例 #2
0
ファイル: AED.cs プロジェクト: Gwae1/audio-analysis
        public static EventCommon[] CallAed(BaseSonogram sonogram, AedConfiguration aedConfiguration, TimeSpan segmentStartOffset, TimeSpan segmentDuration)
        {
            Log.Info("AED start");

            var aedOptions = new AedOptions(sonogram.Configuration.NyquistFreq)
            {
                IntensityThreshold = aedConfiguration.IntensityThreshold,
                SmallAreaThreshold = aedConfiguration.SmallAreaThreshold,
                DoNoiseRemoval     = aedConfiguration.NoiseReductionType == NoiseReductionType.None,
            };

            if (aedConfiguration.BandpassMinimum.HasValue && aedConfiguration.BandpassMaximum.HasValue)
            {
                var bandPassFilter =
                    Tuple.Create(
                        (double)aedConfiguration.BandpassMinimum.Value,
                        (double)aedConfiguration.BandpassMaximum.Value);
                aedOptions.BandPassFilter = new FSharpOption <Tuple <double, double> >(bandPassFilter);
            }

            IEnumerable <Oblong> oblongs = AcousticEventDetection.detectEvents(aedOptions, sonogram.Data);

            Log.Info("AED finished");

            var unitConverters = new UnitConverters(
                segmentStartOffset.TotalSeconds,
                sonogram.SampleRate,
                sonogram.Configuration.WindowSize,
                sonogram.Configuration.WindowOverlap);

            var events = oblongs.Select(
                o =>
            {
                var blob = new BlobEvent()
                {
                    SegmentDurationSeconds = segmentDuration.TotalSeconds,
                    Name = "AED Event",
                };

                unitConverters.SetBounds(blob, o);

                if (aedConfiguration.IncludeHitElementsInOutput)
                {
                    o.HitElements
                    .Select(p => unitConverters.ConvertPointToSpectralPoint(p, 1.0))
                    .ForEach(sp => blob.Points.Add(sp));
                }

                return(blob);
            });

            return(events.ToArray());
        }
コード例 #3
0
ファイル: AED.cs プロジェクト: ninascarpelli/audio-analysis
        public static AcousticEvent[] CallAed(BaseSonogram sonogram, AedConfiguration aedConfiguration, TimeSpan segmentStartOffset, TimeSpan segmentDuration)
        {
            Log.Info("AED start");

            var aedOptions = new AedOptions(sonogram.Configuration.NyquistFreq)
            {
                IntensityThreshold = aedConfiguration.IntensityThreshold,
                SmallAreaThreshold = aedConfiguration.SmallAreaThreshold,
                DoNoiseRemoval     = aedConfiguration.NoiseReductionType == NoiseReductionType.None,
            };

            if (aedConfiguration.BandpassMinimum.HasValue && aedConfiguration.BandpassMaximum.HasValue)
            {
                var bandPassFilter =
                    Tuple.Create(
                        (double)aedConfiguration.BandpassMinimum.Value,
                        (double)aedConfiguration.BandpassMaximum.Value);
                aedOptions.BandPassFilter = new FSharpOption <Tuple <double, double> >(bandPassFilter);
            }

            IEnumerable <Oblong> oblongs = AcousticEventDetection.detectEvents(aedOptions, sonogram.Data);

            Log.Info("AED finished");

            var events = oblongs.Select(
                o =>
            {
                if (!aedConfiguration.IncludeHitElementsInOutput)
                {
                    o.HitElements = null;
                }

                return(new AcousticEvent(
                           segmentStartOffset,
                           o,
                           sonogram.NyquistFrequency,
                           sonogram.Configuration.FreqBinCount,
                           sonogram.FrameDuration,
                           sonogram.FrameStep,
                           sonogram.FrameCount)
                {
                    BorderColour = aedConfiguration.AedEventColor,
                    HitColour = aedConfiguration.AedHitColor,
                    SegmentDurationSeconds = segmentDuration.TotalSeconds,
                });
            }).ToArray();

            return(events);
        }
コード例 #4
0
ファイル: AED.cs プロジェクト: MazenImadJaber/audio-analysis
        public static void Execute(Arguments arguments)
        {
            MainEntry.WarnIfDeveloperEntryUsed();

            TowseyLibrary.Log.Verbosity = 1;
            string date = "# DATE AND TIME: " + DateTime.Now;

            LoggedConsole.WriteLine("# Running acoustic event detection.");
            LoggedConsole.WriteLine(date);

            FileInfo      recodingFile     = arguments.Source;
            var           recodingBaseName = recodingFile.BaseName();
            DirectoryInfo outputDir        = arguments.Output.Combine(EcosoundsAedIdentifier);

            outputDir.Create();

            Log.Info("# Output folder =" + outputDir);
            Log.Info("# Recording file: " + recodingFile.Name);

            // READ PARAMETER VALUES FROM INI FILE
            AedConfiguration configruation = ConfigFile.Deserialize <AedConfiguration>(arguments.Config);
            var aedConfig = GetAedParametersFromConfigFileOrDefaults(configruation);
            var results   = Detect(recodingFile, aedConfig, TimeSpan.Zero);

            // print image
            // save image of sonograms
            var   outputImagePath = outputDir.CombineFile(recodingBaseName + ".Sonogram.png");
            Image image           = DrawSonogram(results.Item3, results.Item1);

            image.Save(outputImagePath.FullName, ImageFormat.Png);
            Log.Info("Image saved to: " + outputImagePath.FullName);

            // output csv
            var outputCsvPath = outputDir.CombineFile(recodingBaseName + ".Events.csv");

            WriteEventsFileStatic(outputCsvPath, results.Item1);
            Log.Info("CSV file saved to: " + outputCsvPath.FullName);

            TowseyLibrary.Log.WriteLine("Finished");
        }