Esempio n. 1
0
def initialize_sox() -> int:
    """Initialize sox for use with effects chains.

    You only need to call this function once to use SoX effects chains multiple times.
    It is safe to call this function multiple times as long as ``shutdown_sox`` is not yet called.
    Once ``shutdown_sox`` is called, you can no longer use SoX effects and calling this function
    results in `RuntimeError`.

    Note:
        This function is not required for simple loading.

    Returns:
        int: Code corresponding to sox_error_t enum. See
        https://fossies.org/dox/sox-14.4.2/sox_8h.html#a8e07e80cebeff3339265d89c387cea93
    """
    global _SOX_INITIALIZED
    if _SOX_INITIALIZED is None:
        raise RuntimeError(
            'SoX effects chain has been already shut down. Can not initialize again.'
        )
    if not _SOX_INITIALIZED:
        import _torch_sox
        code = _torch_sox.initialize_sox()
        if code == _SOX_SUCCESS_CODE:
            _SOX_INITIALIZED = True
            atexit.register(shutdown_sox)
        return code
    return _SOX_SUCCESS_CODE
Esempio n. 2
0
def initialize_sox() -> int:
    """Initialize sox for use with effects chains.  This is not required for simple
    loading.  Importantly, only run `initialize_sox` once and do not shutdown
    after each effect chain, but rather once you are finished with all effects chains.
    """

    import _torch_sox
    return _torch_sox.initialize_sox()