Beispiel #1
0
class TestDetectors(unittest.TestCase):
    def setUp(self):
        from kokako.score import get_audio
        from kokako.detectors.kiwi import SimpleKiwi
        from kokako.detectors.intensity import Energy, LowEnergy, Amplitude
        self.score_kiwi = SimpleKiwi()
        self.score_energy = Energy()
        self.score_low_energy = LowEnergy()
        self.score_amplitude = Amplitude()
        self.audio_gust = get_audio('tests/files/wind-gust-clipping.wav')
        self.audio_kiwi = get_audio('tests/files/male-kiwi.wav')

    def test_kiwi(self):
        assert self.score_kiwi.score(self.audio_kiwi) > self.score_kiwi.score(
            self.audio_gust)

    def test_amplitude(self):
        assert self.score_amplitude.score(self.audio_gust) > 32000

    def test_amplitude_kiwi(self):
        assert self.score_amplitude.score(
            self.audio_gust) > self.score_amplitude.score(self.audio_kiwi)

    def test_energy(self):
        assert self.score_energy.score(
            self.audio_gust) > self.score_energy.score(self.audio_kiwi)

    def test_low_energy(self):
        assert self.score_low_energy.score(
            self.audio_gust) > self.score_low_energy.score(self.audio_kiwi)
class TestDetectors(unittest.TestCase):

    def setUp(self):
        from kokako.score import get_audio
        from kokako.detectors.kiwi import SimpleKiwi
        from kokako.detectors.intensity import Energy, LowEnergy, Amplitude
        self.score_kiwi = SimpleKiwi()
        self.score_energy = Energy()
        self.score_low_energy = LowEnergy()
        self.score_amplitude = Amplitude()
        self.audio_gust = get_audio('tests/files/wind-gust-clipping.wav')
        self.audio_kiwi = get_audio('tests/files/male-kiwi.wav')

    def test_kiwi(self):
        assert self.score_kiwi.score(self.audio_kiwi) > self.score_kiwi.score(self.audio_gust)
    
    def test_amplitude(self):
        assert self.score_amplitude.score(self.audio_gust) > 32000
    
    def test_amplitude_kiwi(self):
        assert self.score_amplitude.score(self.audio_gust) > self.score_amplitude.score(self.audio_kiwi)
    
    def test_energy(self):
        assert self.score_energy.score(self.audio_gust) > self.score_energy.score(self.audio_kiwi)
    
    def test_low_energy(self):
        assert self.score_low_energy.score(self.audio_gust) > self.score_low_energy.score(self.audio_kiwi)
Beispiel #3
0
 def setUp(self):
     from kokako.score import get_audio
     from kokako.detectors.kiwi import SimpleKiwi
     from kokako.detectors.intensity import Energy, LowEnergy, Amplitude
     self.score_kiwi = SimpleKiwi()
     self.score_energy = Energy()
     self.score_low_energy = LowEnergy()
     self.score_amplitude = Amplitude()
     self.audio_gust = get_audio('tests/files/wind-gust-clipping.wav')
     self.audio_kiwi = get_audio('tests/files/male-kiwi.wav')
Beispiel #4
0
 def handle(self, *args, **options):
     detectors = [SimpleKiwi(), Energy(), LowEnergy(), Amplitude()]
     db_detectors = []
     now = time.time()
     for detector in detectors:
         try:
             db_detectors.append(
                 Detector.objects.get(code=detector.code,
                                      version=detector.version))
         except Detector.DoesNotExist:
             db_detectors.append(
                 Detector(code=detector.code,
                          version=detector.version,
                          description=detector.description))
             db_detectors[-1].save()
     detectors = zip(detectors, db_detectors)
     kiwi_detector = Detector.objects.get(
         code='simple-north-island-brown-kiwi')
     recordings = Recording.objects.all().order_by('?')
     for recording in recordings:
         snippets = Snippet.objects.filter(recording=recording).exclude(
             scores__detector=kiwi_detector).order_by('offset')
         if len(snippets):
             fid = io.open(recording.path, 'rb', buffering=BUFFER_SIZE)
             fid.peek(BUFFER_SIZE)
             with closing(fid):
                 for snippet in snippets:
                     try:
                         audio = Audio(*get_audio(recording.path, snippet.
                                                  offset, snippet.duration))
                         count = 0
                         for detector, db_detector in detectors:
                             score = detector.score(audio)
                             if not count:
                                 print '%s %0.1f %0.1f' % (
                                     snippet, time.time() - now, score)
                                 now = time.time()
                             try:
                                 s = Score.objects.get(detector=db_detector,
                                                       snippet=snippet)
                                 s.delete()
                             except Score.DoesNotExist:
                                 pass
                             s = Score(detector=db_detector,
                                       snippet=snippet,
                                       score=score)
                             s.save()
                             count += 1
                     except KeyboardInterrupt:
                         raise
                     except WaveError:
                         print recording.path, 'scoring failed because of a WAV error'
                         break
                     except:
                         print detector, snippet, 'Scoring failed', sys.exc_info(
                         )[0]
 def setUp(self):
     from kokako.score import get_audio
     from kokako.detectors.kiwi import SimpleKiwi
     from kokako.detectors.intensity import Energy, LowEnergy, Amplitude
     self.score_kiwi = SimpleKiwi()
     self.score_energy = Energy()
     self.score_low_energy = LowEnergy()
     self.score_amplitude = Amplitude()
     self.audio_gust = get_audio('tests/files/wind-gust-clipping.wav')
     self.audio_kiwi = get_audio('tests/files/male-kiwi.wav')