コード例 #1
0
def _available_audioread_backends():
    """
    Reduces the overhead of ``audioread.audio_open()`` when called repeatedly
    by caching the results of scanning for FFMPEG etc.
    """
    import audioread
    backends = audioread.available_backends()
    logging.info(f'Using audioread. Available backends: {backends}')
    return backends
コード例 #2
0
    def test_audio_mixed_with_offset_and_snr(self):
        mixer = AudioMixer(base_audio=self.audio1, sampling_rate=8000)
        mixer.add_to_mix(self.audio2, snr=10, offset=0.5)

        unmixed = mixer.unmixed_audio
        assert unmixed.shape == (2, 12000)  # offset 0.5s == 4000 samples
        assert (unmixed[0, :8000] == 1).all()
        assert (unmixed[0, 8000:] == 0).all()
        assert (unmixed[1, :4000] == 0).all()
        np.testing.assert_almost_equal(unmixed[1, 4000:], 0.31622776)
        assert unmixed.dtype == np.float32

        mixed = mixer.mixed_audio
        assert mixed.shape == (1, 12000)
        assert (mixed[0, :4000] == 1).all()
        np.testing.assert_almost_equal(mixed[0, 4000:8000], 1.31622776)
        np.testing.assert_almost_equal(mixed[0, 8000:], 0.31622776)
        assert mixed.dtype == np.float32


@pytest.mark.skipif(
    all('ffmpeg' not in str(backend).lower() for backend in audioread.available_backends()),
    reason='Requires FFmpeg to be installed.'
)
def test_recording_from_file_using_audioread():
    path = 'test/fixtures/mono_c0.opus'
    recording = Recording.from_file(path)
    recording.load_audio()
    # OPUS file read succesfully!
コード例 #3
0
        assert (unmixed[0, 8000:] == 0).all()
        assert (unmixed[1, :4000] == 0).all()
        np.testing.assert_almost_equal(unmixed[1, 4000:], 0.31622776)
        assert unmixed.dtype == np.float32

        mixed = mixer.mixed_audio
        assert mixed.shape == (1, 12000)
        assert (mixed[0, :4000] == 1).all()
        np.testing.assert_almost_equal(mixed[0, 4000:8000], 1.31622776)
        np.testing.assert_almost_equal(mixed[0, 8000:], 0.31622776)
        assert mixed.dtype == np.float32


@pytest.mark.skipif(
    all("ffmpeg" not in str(backend).lower()
        for backend in audioread.available_backends()),
    reason="Requires FFmpeg to be installed.",
)
def test_opus_recording_from_file():
    path = "test/fixtures/mono_c0.opus"
    recording = Recording.from_file(path)
    # OPUS always overrides the sampling rate to 48000
    assert recording.sampling_rate == 48000
    # OPUS may crate extra audio frames / samples...
    assert isclose(recording.duration, 0.5054166666666666)
    samples = recording.load_audio()
    num_channels, num_samples = samples.shape
    assert num_channels == recording.num_channels
    assert num_samples == recording.num_samples
    assert num_samples == 24260
    # OPUS file read succesfully!
コード例 #4
0
ファイル: audioread.py プロジェクト: xjc90s/audiomate
"""
Wrapping opening function of audioread library.
This is used to cache the available backends.
If backend evaluation is done on every call it is very inefficient.
"""

import audioread

available_backends = audioread.available_backends()


def audio_open(path):
    return audioread.audio_open(path, backends=available_backends)