Ejemplo n.º 1
0
    def test_fileobj_large_header(self, ext, dtype):
        """
        For audio file with header size exceeding default buffer size:
        - Querying audio via file object without enlarging buffer size fails.
        - Querying audio via file object after enlarging buffer size succeeds.
        """
        sample_rate = 16000
        num_frames = 3 * sample_rate
        num_channels = 2
        comments = "metadata=" + " ".join(["value" for _ in range(1000)])

        with self.assertRaisesRegex(RuntimeError,
                                    "^Error loading audio file:"):
            sinfo = self._query_fileobj(ext,
                                        dtype,
                                        sample_rate,
                                        num_channels,
                                        num_frames,
                                        comments=comments)

        with self._set_buffer_size(16384):
            sinfo = self._query_fileobj(ext,
                                        dtype,
                                        sample_rate,
                                        num_channels,
                                        num_frames,
                                        comments=comments)
        bits_per_sample = get_bits_per_sample(ext, dtype)
        num_frames = 0 if ext in ['mp3', 'vorbis'] else num_frames

        assert sinfo.sample_rate == sample_rate
        assert sinfo.num_channels == num_channels
        assert sinfo.num_frames == num_frames
        assert sinfo.bits_per_sample == bits_per_sample
        assert sinfo.encoding == get_encoding(ext, dtype)
Ejemplo n.º 2
0
    def test_requests(self, ext, dtype):
        """Querying compressed audio via requests works"""
        sample_rate = 16000
        num_frames = 3.0 * sample_rate
        num_channels = 2
        sinfo = self._query_http(ext, dtype, sample_rate, num_channels, num_frames)

        bits_per_sample = get_bits_per_sample(ext, dtype)
        num_frames = 0 if ext in ['mp3', 'vorbis'] else num_frames

        assert sinfo.sample_rate == sample_rate
        assert sinfo.num_channels == num_channels
        assert sinfo.num_frames == num_frames
        assert sinfo.bits_per_sample == bits_per_sample
        assert sinfo.encoding == get_encoding(ext, dtype)
Ejemplo n.º 3
0
    def test_bytesio_tiny(self, ext, dtype):
        """Querying audio via ByteIO object works for small data"""
        sample_rate = 8000
        num_frames = 4
        num_channels = 2
        sinfo = self._query_bytesio(ext, dtype, sample_rate, num_channels, num_frames)

        bits_per_sample = get_bits_per_sample(ext, dtype)
        num_frames = 0 if ext in ['mp3', 'vorbis'] else num_frames

        assert sinfo.sample_rate == sample_rate
        assert sinfo.num_channels == num_channels
        assert sinfo.num_frames == num_frames
        assert sinfo.bits_per_sample == bits_per_sample
        assert sinfo.encoding == get_encoding(ext, dtype)
Ejemplo n.º 4
0
    def test_fileobj(self, ext, dtype):
        """Querying audio via file object works"""
        sample_rate = 16000
        num_frames = 3 * sample_rate
        num_channels = 2
        sinfo = self._query_fileobj(ext, dtype, sample_rate, num_channels, num_frames)

        bits_per_sample = get_bits_per_sample(ext, dtype)
        num_frames = 0 if ext in ['mp3', 'vorbis'] else num_frames

        assert sinfo.sample_rate == sample_rate
        assert sinfo.num_channels == num_channels
        assert sinfo.num_frames == num_frames
        assert sinfo.bits_per_sample == bits_per_sample
        assert sinfo.encoding == get_encoding(ext, dtype)
Ejemplo n.º 5
0
 def test_wav(self, dtype, sample_rate, num_channels):
     """`soundfile_backend.info` can check wav file correctly"""
     duration = 1
     path = self.get_temp_path("data.wav")
     data = get_wav_data(dtype,
                         num_channels,
                         normalize=False,
                         num_frames=duration * sample_rate)
     save_wav(path, data, sample_rate)
     info = soundfile_backend.info(path)
     assert info.sample_rate == sample_rate
     assert info.num_frames == sample_rate * duration
     assert info.num_channels == num_channels
     assert info.bits_per_sample == get_bits_per_sample("wav", dtype)
     assert info.encoding == get_encoding("wav", dtype)