Exemplo n.º 1
0
def list_audio_backends() -> List[str]:
    """List available backends

    Returns:
        List[str]: The list of available backends.
    """
    backends = []
    if _mod_utils.is_module_available('soundfile'):
        backends.append('soundfile')
    if _mod_utils.is_sox_available():
        backends.append('sox_io')
    return backends
Exemplo n.º 2
0
from torchaudio._internal import module_utils as _mod_utils
from .sox_effects import (
    init_sox_effects,
    shutdown_sox_effects,
    effect_names,
    apply_effects_tensor,
    apply_effects_file,
)

if _mod_utils.is_sox_available():
    import atexit
    init_sox_effects()
    atexit.register(shutdown_sox_effects)

__all__ = [
    'init_sox_effects',
    'shutdown_sox_effects',
    'effect_names',
    'apply_effects_tensor',
    'apply_effects_file',
]
Exemplo n.º 3
0
    def complex_dtype(self):
        if self.dtype in ['float32', 'float', torch.float, torch.float32]:
            return torch.cfloat
        if self.dtype in ['float64', 'double', torch.double, torch.float64]:
            return torch.cdouble
        raise ValueError(f'No corresponding complex dtype for {self.dtype}')


class TorchaudioTestCase(TestBaseMixin, PytorchTestCase):
    pass


def skipIfNoExec(cmd):
    return unittest.skipIf(shutil.which(cmd) is None, f'`{cmd}` is not available')


def skipIfNoModule(module, display_name=None):
    display_name = display_name or module
    return unittest.skipIf(not is_module_available(module), f'"{display_name}" is not available')


skipIfNoCuda = unittest.skipIf(not torch.cuda.is_available(), reason='CUDA not available')
skipIfNoSox = unittest.skipIf(not is_sox_available(), reason='Sox not available')
skipIfNoKaldi = unittest.skipIf(not is_kaldi_available(), reason='Kaldi not available')
skipIfRocm = unittest.skipIf(os.getenv('TORCHAUDIO_TEST_WITH_ROCM', '0') == '1',
                             reason="test doesn't currently work on the ROCm stack")
skipIfNoQengine = unittest.skipIf(
    'fbgemm' not in torch.backends.quantized.supported_engines,
    reason="`fbgemm` is not available."
)
Exemplo n.º 4
0
from torchaudio.utils import sox_utils
from torchaudio.backend import sox_io_backend
from torchaudio._internal.module_utils import is_sox_available
from parameterized import parameterized

from torchaudio_unittest.common_utils import (
    TempDirMixin,
    TorchaudioTestCase,
    skipIfNoSox,
    get_wav_data,
)
from .common import name_func

skipIfNoMP3 = unittest.skipIf(
    not is_sox_available() or 'mp3' not in sox_utils.list_read_formats()
    or 'mp3' not in sox_utils.list_write_formats(),
    '"sox_io" backend does not support MP3')


@skipIfNoSox
class SmokeTest(TempDirMixin, TorchaudioTestCase):
    """Run smoke test on various audio format

    The purpose of this test suite is to verify that sox_io_backend functionalities do not exhibit
    abnormal behaviors.

    This test suite should be able to run without any additional tools (such as sox command),
    however without such tools, the correctness of each function cannot be verified.
    """
    def run_smoke_test(self,
Exemplo n.º 5
0
    backend = None

    def setUp(self):
        super().setUp()
        set_audio_backend(self.backend)


class TorchaudioTestCase(TestBaseMixin, PytorchTestCase):
    pass


def skipIfNoExec(cmd):
    return unittest.skipIf(
        shutil.which(cmd) is None, f'`{cmd}` is not available')


def skipIfNoModule(module, display_name=None):
    display_name = display_name or module
    return unittest.skipIf(not is_module_available(module),
                           f'"{display_name}" is not available')


skipIfNoSoxBackend = unittest.skipIf(
    'sox' not in torchaudio.list_audio_backends(), 'Sox backend not available')
skipIfNoCuda = unittest.skipIf(not torch.cuda.is_available(),
                               reason='CUDA not available')
skipIfNoSox = unittest.skipIf(not is_sox_available(),
                              reason='Sox not available')
skipIfNoKaldi = unittest.skipIf(not is_kaldi_available(),
                                reason='Kaldi not available')