Example #1
0
    def __init__(self, wave):

        assert wave.getnchannels() == 1
        WaveStream.__init__(self, wave)

        chunksize = self.getframerate() / 2000
        threshold = 5

        chunk = self.wave.readframes(chunksize)
        position = len(chunk)
        rms = calculate_rms_dB(chunk)

        while True:
            newchunk = self.wave.readframes(chunksize)
            position += len(newchunk)
            newrms = calculate_rms_dB(newchunk)
            if newrms <= -96.0: continue
            if newrms - rms > threshold:
                self.audio_onset_sample = position - len(chunk) - len(newchunk)
                self.buf = numpy.hstack([chunk, newchunk])
                return
            chunk = newchunk
            rms = newrms

        raise NoAudioOnset, "No audio onset could be found"
Example #2
0
    if filename.lower().endswith(".flac"): return FLACDecoder(filename)
    if filename.lower().endswith(".ogg"): return VorbisDecoder(filename)
    return WaveStream(wave.open(file(filename)))


if __name__ == "__main__":
    import sys

    print "\nMP3Decoder"
    print sys.argv[1]
    o = AudioOnsetDiscarder(MonoStream(FloatStream(NumPyStream(decode(sys.argv[1])))))

    print o.audio_onset_sample
    data = o.readframes(44100 * 3)
    print len(data)
    rms = calculate_rms_dB(data, 1.0)
    print rms
    #print data[512:768]*32768

    from audioprocessing.util import play

    data = (data * 32768).astype("int16").tostring()
    play(data)

__all__ = [
    'WaveStream',
    'NumPyStream',
    'FloatStream',
    'MonoStream',
    'AudioOnsetDiscarder',
    'NoAudioOnset',