예제 #1
0
    def test_RMS(self):
        testFile = join(self.tmp, 'red_16000.wav')
        data, sampleRate = microphone.readWavFile(testFile)

        rms = microphone.getRMS(data)
        assert 588.60 < rms < 588.61

        rmsb = microphone.getRMSBins(data, chunk=64)
        assert 10.2 < rmsb[0] < 10.3
        assert len(rmsb) == 480
예제 #2
0
    def test_DFT(self):
        testFile = join(self.tmp, 'red_16000.wav')
        data, sampleRate = microphone.readWavFile(testFile)

        with pytest.raises(OverflowError):
            microphone.getDft([])
        microphone.getDft(data)
        microphone.getDftBins(data)
        microphone.getDftBins(data, sampleRate=16000)
        microphone.getDft(data, sampleRate=sampleRate)
        microphone.getDft(data, wantPhase=True)
예제 #3
0
    def test_wav_flac(self):
        filename = os.path.join(self.tmp, 'test_bad_readWav')
        with open(filename, 'wb') as fd:
            fd.write(b'x')
        with pytest.raises(microphone.SoundFileError):
            microphone.readWavFile(filename)

        testFile = join(self.tmp, 'green_48000.wav')
        newFile = microphone.wav2flac(testFile, keep=True)
        microphone.flac2wav(newFile, keep=True)

        newFile0 = microphone.wav2flac(testFile, keep=True, level=0)
        newFile8 = microphone.wav2flac(testFile, keep=True, level=8)
        assert os.path.getsize(newFile0) >= os.path.getsize(newFile8)

        microphone.wav2flac('.', keep=True)
        microphone.flac2wav('.', keep=True)
        microphone.wav2flac('', keep=True)
        microphone.flac2wav('', keep=True)

        microphone.wav2flac(self.tmp, keep=True)
예제 #4
0
    # When in the file did the onset tone start and stop?
    onset, offset = mic.getMarkerOnset(
        chunk=64, secs=0.2)  # increase secs if miss the markers
    onsets.append(onset)

    # display options:
    text.draw()
    win.flip()
    print("%.3f %.3f" % (onset, offset))
    if len(event.getKeys(['escape'])):
        core.quit()
    if len(event.getKeys()):
        msg2.draw()
        win.flip()
        data, sampleRate = microphone.readWavFile(filename)
        plotYX(data, list(range(len(data))), "time domain @ %iHz" % sampleRate)
        mag, freqV = microphone.getDft(data, sampleRate)
        plotYX(mag, freqV,
               "frequency domain (marker at %i Hz)" % mic.getMarkerInfo()[0])

    # no need to keep the recorded file:
    os.unlink(filename)

print("\nmarker onset = %.3fs %.3f (mean SD), relative to start of file" %
      (np.mean(onsets), np.std(onsets)))

win.close()
core.quit()

# The contents of this file are in the public domain.
예제 #5
0
    while mic.recorder.running:
        core.wait(.01, 0)

    # When in the file did the onset tone start and stop?
    onset, offset = mic.getMarkerOnset(chunk=64, secs=0.2)  # increase secs if miss the markers
    onsets.append(onset)

    # display options:
    text.draw()
    win.flip()
    print("%.3f %.3f" % (onset, offset))
    if len(event.getKeys(['escape'])):
        core.quit()
    if len(event.getKeys()):
        msg2.draw()
        win.flip()
        data, sampleRate = microphone.readWavFile(filename)
        plotYX(data, list(range(len(data))), "time domain @ %iHz" % sampleRate)
        mag, freqV = microphone.getDft(data, sampleRate)
        plotYX(mag, freqV, "frequency domain (marker at %i Hz)" % mic.getMarkerInfo()[0])

    # no need to keep the recorded file:
    os.unlink(filename)

print("\nmarker onset = %.3fs %.3f (mean SD), relative to start of file" % (np.mean(onsets), np.std(onsets)))

win.close()
core.quit()

# The contents of this file are in the public domain.