Example #1
0
 def setup_class(self):
     try:
         assert _getFlacPath()
     except Exception:
         # some of the utils could be designed not to need flac but they
         # currently work on a file that is distributed in flac format
         pytest.skip()
     self.tmp = mkdtemp(prefix='psychopy-tests-microphone')
     for testFile in ['red_16000.flac.dist', 'green_48000.flac.dist']:
         t = join(TESTS_DATA_PATH, testFile)
         new_wav = join(self.tmp, testFile.replace('.dist', ''))
         shutil.copyfile(t, new_wav)
         microphone.flac2wav(new_wav)
Example #2
0
    def setup_class(self):
        self.contextName='pyo'
        try:
            assert sound.Sound == sound.SoundPyo
        except:
            pytest.xfail('need to be using pyo')
        self.tmp = mkdtemp(prefix='psychopy-tests-sound')

        # ensure some good test data:
        testFile = 'green_48000.flac.dist'
        new_wav = os.path.join(self.tmp, testFile.replace('.dist', ''))
        shutil.copyfile(os.path.join(TESTS_DATA_PATH, testFile), new_wav)
        w = microphone.flac2wav(new_wav)
        r, d = wavfile.read(w)
        assert r == 48000
        assert len(d) == 92160
Example #3
0
    def setup_class(self):
        self.contextName = 'pyo'
        try:
            assert sound.Sound == sound.SoundPyo
        except Exception:
            pytest.xfail('need to be using pyo')
        self.tmp = mkdtemp(prefix='psychopy-tests-sound')

        # ensure some good test data:
        testFile = 'green_48000.flac.dist'
        new_wav = os.path.join(self.tmp, testFile.replace('.dist', ''))
        shutil.copyfile(os.path.join(TESTS_DATA_PATH, testFile), new_wav)
        w = microphone.flac2wav(new_wav)
        r, d = wavfile.read(w)
        assert r == 48000
        assert len(d) == 92160

        self.testFile = os.path.join(self.tmp, 'green_48000.wav')
Example #4
0
    def setup_class(self):
        prefs.hardware['audioLib'] = ['pyo']
        reload(sound)  # to force our new preference to be used
        self.contextName='pyo'
        try:
            assert sound.Sound == sound.SoundPyo
        except Exception:
            pytest.xfail('need to be using pyo')
        self.tmp = mkdtemp(prefix='psychopy-tests-sound')

        # ensure some good test data:
        testFile = 'green_48000.flac.dist'
        new_wav = os.path.join(self.tmp, testFile.replace('.dist', ''))
        shutil.copyfile(os.path.join(TESTS_DATA_PATH, testFile), new_wav)
        w = microphone.flac2wav(new_wav)
        r, d = wavfile.read(w)
        assert r == 48000
        assert len(d) == 92160

        self.testFile = os.path.join(self.tmp, 'green_48000.wav')
Example #5
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)