Esempio n. 1
0
    def test_write_wav_writer_raises_exception(self):
        """write_wav_file where the file object write method raises an exception."""
        def _failing_write(unused_bytes):
            raise OSError('write method failed')

        writer = MockWriter(_failing_write)
        with self.assertRaisesRegex(OSError, 'write method failed'):
            dsp.write_wav_file(writer, np.zeros((10, 1), dtype=np.int16), 8000)
Esempio n. 2
0
    def test_write_wav_bad_arg(self):
        """write_wav_file where the argument is not a file-like object."""
        class Nonsense(object):
            pass

        with self.assertRaisesRegex(TypeError, 'Nonsense found'):
            dsp.write_wav_file(Nonsense(), np.zeros((10, 1), dtype=np.int16),
                               8000)
Esempio n. 3
0
def convert_one_example(sphere_file: str, wav_file: str) -> None:
    """Converts sphere file to WAV."""
    sample_rate_hz, samples = read_nist_sphere.read_nist_sphere(sphere_file)
    dsp.write_wav_file(wav_file, samples, sample_rate_hz)

    # TIMIT includes .phn files that gives timestamps and labels of the phones
    # that occur in the recording. We copy these files to the output directory.
    src_phn = os.path.splitext(sphere_file)[0] + '.PHN'
    dest_phn = os.path.splitext(wav_file)[0] + '.phn'
    shutil.copyfile(src_phn, dest_phn)
Esempio n. 4
0
    def test_write_wav_local_file(self):
        """Write WAV to a given filename with write_wav_file()."""
        try:
            write_filename = os.path.join(self.temp_dir, 'write.wav')
            dsp.write_wav_file(write_filename, self.wav_samples, 44100)

            samples, sample_rate_hz = dsp.read_wav_file(write_filename)
            np.testing.assert_array_equal(samples, self.wav_samples)
            self.assertEqual(sample_rate_hz, 44100)
        finally:
            if os.path.isfile(write_filename):
                os.remove(write_filename)
Esempio n. 5
0
 def test_write_wav_write_not_callable(self):
     """write_wav_file where the write attribute is not callable."""
     writer = MockWriter(None)
     with self.assertRaisesRegex(TypeError, 'not callable'):
         dsp.write_wav_file(writer, np.zeros((10, 1), dtype=np.int16), 8000)