Esempio n. 1
0
 def test_reader(self):
     
     cases = [
         ('One Channel.wav', 1, 100, 22050, np.int16),
         ('Two Channels.wav', 2, 10, 24000, np.int16),
         ('Four Channels.wav', 4, 100, 22050, np.int16)
     ]
     
     for file_name, num_channels, length, sample_rate, dtype in cases:
         
         file_path = utils.create_test_audio_file_path(file_name)
         
         self.assertTrue(WaveAudioFileType.is_supported_file(file_path))
         
         # Test reader constructed from file.
         with WaveAudioFileType.reader_class(file_path) as reader:
             self._test_reader(
                 reader, file_path, WaveAudioFileType, num_channels, length,
                 sample_rate, dtype)
         
         # Test reader constructed from file contents.
         with open(file_path, 'rb') as file_:
             data = file_.read()
         file_ = io.BytesIO(data)
         with WaveAudioFileType.reader_class(file_) as reader:
             self._test_reader(
                 reader, None, WaveAudioFileType, num_channels, length,
                 sample_rate, dtype)
         
         self._test_create_multichannel_array_signal(
             file_path, num_channels, length, sample_rate, dtype)
Esempio n. 2
0
    def test_reader(self):

        cases = [('One Channel.wav', 1, 100, 22050, np.int16),
                 ('Two Channels.wav', 2, 10, 24000, np.int16),
                 ('Four Channels.wav', 4, 100, 22050, np.int16)]

        for file_name, num_channels, length, sample_rate, dtype in cases:

            file_path = utils.create_test_audio_file_path(file_name)

            self.assertTrue(WaveAudioFileType.is_supported_file(file_path))

            # Test reader constructed from file.
            with WaveAudioFileType.reader_class(file_path) as reader:
                self._test_reader(reader, file_path, WaveAudioFileType,
                                  num_channels, length, sample_rate, dtype)

            # Test reader constructed from file contents.
            with open(file_path, 'rb') as file_:
                data = file_.read()
            file_ = io.BytesIO(data)
            with WaveAudioFileType.reader_class(file_) as reader:
                self._test_reader(reader, None, WaveAudioFileType,
                                  num_channels, length, sample_rate, dtype)

            self._test_create_multichannel_array_signal(
                file_path, num_channels, length, sample_rate, dtype)
Esempio n. 3
0
    def test_out_of_range_wav_file_read_errors(self):

        file_path = utils.create_test_audio_file_path('One Channel.wav')

        cases = [(-10, None), (1000, None), (0, 1000)]

        for start_index, length in cases:
            reader = WaveAudioFileReader(file_path)
            self._assert_raises(ValueError, reader.read, start_index, length)
Esempio n. 4
0
    def test_get_audio_file_type(self):

        cases = [('One Channel.wav', WaveAudioFileType),
                 ('Two Channels.wav', WaveAudioFileType), ('Empty', None)]

        for file_name, expected in cases:
            file_path = utils.create_test_audio_file_path(file_name)
            file_type = audio_file_utils.get_audio_file_type(file_path)
            self.assertEqual(file_type, expected)
 def test_get_audio_file_type(self):
     
     cases = [
         ('One Channel.wav', WaveAudioFileType),
         ('Two Channels.wav', WaveAudioFileType),
         ('Empty', None)
     ]
     
     for file_name, expected in cases:
         file_path = utils.create_test_audio_file_path(file_name)
         file_type = audio_file_utils.get_audio_file_type(file_path)
         self.assertEqual(file_type, expected)
Esempio n. 6
0
 def test_out_of_range_wav_file_read_errors(self):
     
     file_path = utils.create_test_audio_file_path('One Channel.wav')
     
     cases = [
         (-10, None),
         (1000, None),
         (0, 1000)
     ]
     
     for start_index, length in cases:
         reader = WaveAudioFileReader(file_path)
         self._assert_raises(ValueError, reader.read, start_index, length)
 def test_create_array_signal(self):
     
     cases = [
         ('One Channel.wav', 100, 22050, np.int16),
     ]
     
     for file_name, length, sample_rate, dtype in cases:
         
         file_path = utils.create_test_audio_file_path(file_name)
         
         audio = audio_file_utils.create_array_signal(file_path)
         
         self.assertIsInstance(audio, ArraySignal)
         self.assertEqual(len(audio), length)
         self.assertEqual(audio.time_axis.sample_rate, sample_rate)
         self.assertEqual(audio.dtype, dtype)
         
         expected = utils.create_samples((length,), factor=1000, dtype=dtype)
         utils.assert_arrays_equal(audio[:], expected, strict=True)
Esempio n. 8
0
    def test_create_array_signal(self):

        cases = [
            ('One Channel.wav', 100, 22050, np.int16),
        ]

        for file_name, length, sample_rate, dtype in cases:

            file_path = utils.create_test_audio_file_path(file_name)

            audio = audio_file_utils.create_array_signal(file_path)

            self.assertIsInstance(audio, ArraySignal)
            self.assertEqual(len(audio), length)
            self.assertEqual(audio.time_axis.sample_rate, sample_rate)
            self.assertEqual(audio.dtype, dtype)

            expected = utils.create_samples((length, ),
                                            factor=1000,
                                            dtype=dtype)
            utils.assert_arrays_equal(audio[:], expected, strict=True)
Esempio n. 9
0
    def test_create_multichannel_array_signal(self):

        cases = [('One Channel.wav', 1, 100, 22050, np.int16),
                 ('Two Channels.wav', 2, 10, 24000, np.int16),
                 ('Four Channels.wav', 4, 100, 22050, np.int16)]

        for file_name, num_channels, length, sample_rate, dtype in cases:

            file_path = utils.create_test_audio_file_path(file_name)

            audio = audio_file_utils.create_multichannel_array_signal(
                file_path)

            self.assertIsInstance(audio, MultichannelArraySignal)
            self.assertEqual(len(audio), num_channels)
            self.assertEqual(audio.time_axis.length, length)
            self.assertEqual(audio.time_axis.sample_rate, sample_rate)
            self.assertEqual(audio.dtype, dtype)

            expected = utils.create_samples((num_channels, length),
                                            factor=1000,
                                            dtype=dtype)
            utils.assert_arrays_equal(audio[:], expected, strict=True)
Esempio n. 10
0
 def test_create_multichannel_array_signal(self):
     
     cases = [
         ('One Channel.wav', 1, 100, 22050, np.int16),
         ('Two Channels.wav', 2, 10, 24000, np.int16),
         ('Four Channels.wav', 4, 100, 22050, np.int16)
     ]
     
     for file_name, num_channels, length, sample_rate, dtype in cases:
         
         file_path = utils.create_test_audio_file_path(file_name)
         
         audio = audio_file_utils.create_multichannel_array_signal(file_path)
         
         self.assertIsInstance(audio, MultichannelArraySignal)
         self.assertEqual(len(audio), num_channels)
         self.assertEqual(audio.time_axis.length, length)
         self.assertEqual(audio.time_axis.sample_rate, sample_rate)
         self.assertEqual(audio.dtype, dtype)
         
         expected = utils.create_samples(
             (num_channels, length), factor=1000, dtype=dtype)
         utils.assert_arrays_equal(audio[:], expected, strict=True)
Esempio n. 11
0
 def test_non_wav_file_error(self):
     file_path = utils.create_test_audio_file_path('Empty')
     self._assert_raises(UnsupportedAudioFileError, WaveAudioFileReader,
                         file_path)
Esempio n. 12
0
 def test_truncated_wav_file_error(self):
     file_path = utils.create_test_audio_file_path('Truncated.wav')
     reader = WaveAudioFileReader(file_path)
     self._assert_raises(OSError, reader.read)
Esempio n. 13
0
 def test_truncated_wav_file_error(self):
     file_path = utils.create_test_audio_file_path('Truncated.wav')
     reader = WaveAudioFileReader(file_path)
     self._assert_raises(OSError, reader.read)
Esempio n. 14
0
 def test_non_wav_file_error(self):
     file_path = utils.create_test_audio_file_path('Empty')
     self._assert_raises(
         UnsupportedAudioFileError, WaveAudioFileReader, file_path)
Esempio n. 15
0
 def _assert_function_raises(self, cls, function, file_name):
     file_path = utils.create_test_audio_file_path(file_name)
     self._assert_raises(cls, function, file_path)
Esempio n. 16
0
 def test_closed_wav_file_read_error(self):
     file_path = utils.create_test_audio_file_path('One Channel.wav')
     reader = WaveAudioFileReader(file_path)
     reader.close()
     self._assert_raises(OSError, reader.read)
Esempio n. 17
0
 def test_empty_wav_file_error(self):
     file_path = utils.create_test_audio_file_path('Empty.wav')
     self._assert_raises(OSError, WaveAudioFileReader, file_path)
Esempio n. 18
0
 def _assert_function_raises(self, cls, function, file_name):
     file_path = utils.create_test_audio_file_path(file_name)
     self._assert_raises(cls, function, file_path)
Esempio n. 19
0
 def test_closed_wav_file_read_error(self):
     file_path = utils.create_test_audio_file_path('One Channel.wav')
     reader = WaveAudioFileReader(file_path)
     reader.close()
     self._assert_raises(OSError, reader.read)
Esempio n. 20
0
 def test_empty_wav_file_error(self):
     file_path = utils.create_test_audio_file_path('Empty.wav')
     self._assert_raises(OSError, WaveAudioFileReader, file_path)