Exemplo n.º 1
0
        /// <summary>
        /// This method is called once per segment (typically one-minute segments).
        /// </summary>
        /// <param name="audioRecording">one minute of audio recording.</param>
        /// <param name="config">config file that contains parameters used by all profiles.</param>
        /// <param name="segmentStartOffset">when recording starts.</param>
        /// <param name="getSpectralIndexes">not sure what this is.</param>
        /// <param name="outputDirectory">where the recognizer results can be found.</param>
        /// <param name="imageWidth"> assuming ????.</param>
        /// <returns>recognizer results.</returns>
        public override RecognizerResults Recognize(
            AudioRecording audioRecording,
            Config config,
            TimeSpan segmentStartOffset,
            Lazy <IndexCalculateResult[]> getSpectralIndexes,
            DirectoryInfo outputDirectory,
            int?imageWidth)
        {
            //class NinoxBoobookConfig is defined at bottom of this file.
            var genericConfig = (NinoxBoobookConfig)config;
            var recognizer    = new GenericRecognizer();

            RecognizerResults combinedResults = recognizer.Recognize(
                audioRecording,
                genericConfig,
                segmentStartOffset,
                getSpectralIndexes,
                outputDirectory,
                imageWidth);

            // DO POST-PROCESSING of EVENTS

            // Filter out the chirp events for possible combining.
            var(chirpEvents, others) = combinedResults.NewEvents.FilterForEventType <ChirpEvent, EventCommon>();

            // Uncomment the next line when want to obtain the event frequency profiles.
            // WriteFrequencyProfiles(chirpEvents);

            // Calculate frequency profile score for each event
            foreach (var ev in chirpEvents)
            {
                SetFrequencyProfileScore((ChirpEvent)ev);
            }

            // Combine overlapping events. If the dB threshold is set low, may get lots of little events.
            var newEvents = CompositeEvent.CombineOverlappingEvents(chirpEvents.Cast <EventCommon>().ToList());

            if (genericConfig.CombinePossibleSyllableSequence)
            {
                // convert events to spectral events for possible combining.
                var(spectralEvents, _) = combinedResults.NewEvents.FilterForEventType <SpectralEvent, EventCommon>();

                var startDiff = genericConfig.SyllableStartDifference;
                var hertzDiff = genericConfig.SyllableHertzGap;
                newEvents = CompositeEvent.CombineSimilarProximalEvents(spectralEvents, TimeSpan.FromSeconds(startDiff), (int)hertzDiff);
            }

            combinedResults.NewEvents = newEvents;

            //UNCOMMENT following line if you want special debug spectrogram, i.e. with special plots.
            //  NOTE: Standard spectrograms are produced by setting SaveSonogramImages: "True" or "WhenEventsDetected" in <Towsey.PteropusSpecies.yml> config file.
            //GenericRecognizer.SaveDebugSpectrogram(territorialResults, genericConfig, outputDirectory, audioRecording.BaseName);
            return(combinedResults);
        }
Exemplo n.º 2
0
        public void TestEventMerging()
        {
            // make a list of three events
            var events           = new List <SpectralEvent>();
            var segmentStartTime = TimeSpan.FromSeconds(10);
            var event1           = new SpectralEvent(segmentStartOffset: segmentStartTime, eventStartRecordingRelative: 11.0, eventEndRecordingRelative: 16.0, minFreq: 1000, maxFreq: 6000)
            {
                Name  = "Event1",
                Score = 1.0,
            };

            events.Add(event1);

            var event2 = new SpectralEvent(segmentStartOffset: segmentStartTime, eventStartRecordingRelative: 12.0, eventEndRecordingRelative: 15.0, minFreq: 1500, maxFreq: 8000)
            {
                Name  = "Event2",
                Score = 5.0,
            };

            events.Add(event2);

            var event3 = new SpectralEvent(segmentStartOffset: segmentStartTime, eventStartRecordingRelative: 17.0, eventEndRecordingRelative: 19.0, minFreq: 1000, maxFreq: 8000)
            {
                Name  = "Event3",
                Score = 9.0,
            };

            events.Add(event3);

            // combine Overlapping acoustic events
            var newEvents = CompositeEvent.CombineOverlappingEvents(events: events.Cast <EventCommon>().ToList());

            events = newEvents.Cast <SpectralEvent>().ToList();

            //require two events, the first being a composite of two events.
            Assert.AreEqual(2, events.Count);
            Assert.AreEqual(typeof(CompositeEvent), events[0].GetType());

            Assert.AreEqual(2, ((CompositeEvent)events[0]).ComponentEvents.Count);

            Assert.AreEqual(11.0, events[0].EventStartSeconds);
            Assert.AreEqual(16.0, events[0].EventEndSeconds);
            Assert.AreEqual(1000, events[0].LowFrequencyHertz);
            Assert.AreEqual(8000, events[0].HighFrequencyHertz);
            Assert.AreEqual(5.0, events[0].Score);

            Assert.AreEqual(typeof(SpectralEvent), events[1].GetType());
            Assert.AreEqual(17.0, events[1].EventStartSeconds);
            Assert.AreEqual(19.0, events[1].EventEndSeconds);
            Assert.AreEqual(1000, events[1].LowFrequencyHertz);
            Assert.AreEqual(8000, events[1].HighFrequencyHertz);
            Assert.AreEqual(9.0, events[1].Score);
        }