diff --git a/.github/scripts/unittest-linux/install.sh b/.github/scripts/unittest-linux/install.sh
index 885296219c..70a8793c22 100755
--- a/.github/scripts/unittest-linux/install.sh
+++ b/.github/scripts/unittest-linux/install.sh
@@ -75,7 +75,7 @@ fi
# Note: installing librosa via pip fail because it will try to compile numba.
(
set -x
- conda install -y -c conda-forge ${NUMBA_DEV_CHANNEL} 'librosa==0.10.0' parameterized 'requests>=2.20' 'ffmpeg>=5,<7'
+ conda install -y -c conda-forge ${NUMBA_DEV_CHANNEL} sox libvorbis 'librosa==0.10.0' parameterized 'requests>=2.20' 'ffmpeg>=5,<7'
pip install kaldi-io SoundFile coverage pytest pytest-cov 'scipy==1.7.3' expecttest unidecode inflect Pillow sentencepiece pytorch-lightning 'protobuf<4.21.0' demucs tinytag pyroomacoustics flashlight-text git+https://github.com/kpu/kenlm
)
# Install fairseq
diff --git a/.github/workflows/build_docs.yml b/.github/workflows/build_docs.yml
index d87f6d0125..ea0f88d1c1 100644
--- a/.github/workflows/build_docs.yml
+++ b/.github/workflows/build_docs.yml
@@ -63,7 +63,7 @@ jobs:
echo "::endgroup::"
echo "::group::Install TorchAudio"
- conda install --quiet --yes pkg-config cmake>=3.18.0 ninja
+ conda install --quiet --yes cmake>=3.18.0 ninja
pip3 install --progress-bar off -v -e . --no-use-pep517
echo "::endgroup::"
@@ -75,7 +75,7 @@ jobs:
conda install \
--quiet --yes \
-c conda-forge \
- pandoc doxygen pysoundfile
+ sox libvorbis pandoc doxygen pysoundfile
pip install --progress-bar off \
git+https://github.com/kpu/kenlm/ flashlight-text \
-r docs/requirements.txt -r docs/requirements-tutorials.txt
diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml
index 28bd6cacb6..63a012660c 100644
--- a/.github/workflows/integration-test.yml
+++ b/.github/workflows/integration-test.yml
@@ -24,7 +24,7 @@ jobs:
- name: Install dependencies
run: |
sudo add-apt-repository -y ppa:jonathonf/ffmpeg-4
- sudo apt install -y -qq pkg-config libavfilter-dev libavdevice-dev
+ sudo apt install -y -qq libavfilter-dev libavdevice-dev
- name: Install packages
run: |
python -m pip install --quiet --upgrade pip
diff --git a/.github/workflows/unittest-linux-cpu.yml b/.github/workflows/unittest-linux-cpu.yml
index 50207c0131..b96dd200cb 100644
--- a/.github/workflows/unittest-linux-cpu.yml
+++ b/.github/workflows/unittest-linux-cpu.yml
@@ -50,6 +50,8 @@ jobs:
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_AUDIO_OUT_DEVICE=true
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_MACOS=true
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_TEMPORARY_DISABLED=true
+ export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_SOX_DECODER=true
+ export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_SOX_ENCODER=true
echo '::endgroup::'
set -euxo pipefail
diff --git a/.github/workflows/unittest-linux-gpu.yml b/.github/workflows/unittest-linux-gpu.yml
index 86ab9dcd16..a77d1a4854 100644
--- a/.github/workflows/unittest-linux-gpu.yml
+++ b/.github/workflows/unittest-linux-gpu.yml
@@ -38,6 +38,8 @@ jobs:
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_CUDA_SMALL_MEMORY=true
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_ON_PYTHON_310=true
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_TEMPORARY_DISABLED=true
+ export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_SOX_DECODER=true
+ export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_SOX_ENCODER=true
# Set CHANNEL
if [[(${GITHUB_EVENT_NAME} = 'pull_request' && (${GITHUB_BASE_REF} = 'release'*)) || (${GITHUB_REF} = 'refs/heads/release'*) ]]; then
@@ -63,7 +65,7 @@ jobs:
echo "::endgroup::"
echo "::group::Install TorchAudio"
- conda install --quiet --yes pkg-config 'cmake>=3.18.0' ninja
+ conda install --quiet --yes 'cmake>=3.18.0' ninja
pip3 install --progress-bar off -v -e . --no-use-pep517
echo "::endgroup::"
@@ -76,7 +78,7 @@ jobs:
--quiet --yes \
-c conda-forge \
-c numba/label/dev \
- 'librosa==0.10.0' parameterized 'requests>=2.20'
+ sox libvorbis 'librosa==0.10.0' parameterized 'requests>=2.20'
pip3 install --progress-bar off \
kaldi-io \
SoundFile \
diff --git a/.github/workflows/unittest-macos-cpu.yml b/.github/workflows/unittest-macos-cpu.yml
index 4e3cc59879..274d5eb648 100644
--- a/.github/workflows/unittest-macos-cpu.yml
+++ b/.github/workflows/unittest-macos-cpu.yml
@@ -49,6 +49,8 @@ jobs:
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_MOD_sentencepiece=true
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_AUDIO_OUT_DEVICE=true
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_TEMPORARY_DISABLED=true
+ export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_SOX_DECODER=true
+ export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_SOX_ENCODER=true
echo '::endgroup::'
set -euxo pipefail
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 3e615a799e..071cb6983e 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -49,13 +49,11 @@ torchaudio.
conda install pytorch -c pytorch-nightly
```
-### Install build dependencies
+### Install build/runtime dependencies
```bash
# Install build-time dependencies
pip install cmake ninja
-# [optional for sox]
-conda install pkg-config
# [optional for ffmpeg]
conda install ffmpeg
```
diff --git a/docs/source/build.jetson.rst b/docs/source/build.jetson.rst
index b1b83d7498..01dd2fb002 100644
--- a/docs/source/build.jetson.rst
+++ b/docs/source/build.jetson.rst
@@ -121,7 +121,7 @@ Verify the installation by checking the version and CUDA device accessibility.
.. code-block::
- pip install cmake ninja pkg-config
+ pip install cmake ninja
2. Install dependencies
~~~~~~~~~~~~~~~~~~~~~~~
diff --git a/docs/source/build.linux.rst b/docs/source/build.linux.rst
index cd9a93bab8..5aa10dd7a4 100644
--- a/docs/source/build.linux.rst
+++ b/docs/source/build.linux.rst
@@ -22,7 +22,7 @@ Here, we install nightly build.
.. code-block::
- conda install cmake ninja pkg-config
+ conda install cmake ninja
4. Clone the torchaudio repository
----------------------------------
diff --git a/docs/source/build.rst b/docs/source/build.rst
index 6fb3e57449..32f283ba0b 100644
--- a/docs/source/build.rst
+++ b/docs/source/build.rst
@@ -10,7 +10,6 @@ TorchAudio integrates PyTorch for numerical computation and third party librarie
- `GCC `_ (Linux)
- `Clang `_ (macOS)
- `MSVC `_ 2019 or newer (Windows)
-- `pkg-config `_ (Linux/macOS, if building sox extension)
- `CUDA toolkit `_ and `cuDNN `_ (if building CUDA extension)
Most of the tools are available in `Conda `_, so we recommend using conda.
diff --git a/packaging/torchaudio/meta.yaml b/packaging/torchaudio/meta.yaml
index 29ffc542e5..031fed93d6 100644
--- a/packaging/torchaudio/meta.yaml
+++ b/packaging/torchaudio/meta.yaml
@@ -14,7 +14,6 @@ requirements:
host:
- python
- setuptools
- - pkg-config # [not win]
- cmake
- ninja
- pytorch-mutex 1.0 {{ build_variant }} # [not osx ]
diff --git a/setup.py b/setup.py
index 0a8080d06e..38a4ab3449 100644
--- a/setup.py
+++ b/setup.py
@@ -4,7 +4,6 @@
import re
import shutil
import subprocess
-import sys
from pathlib import Path
import torch
@@ -83,18 +82,6 @@ def _get_packages(branch_name, tag):
return find_packages(exclude=exclude)
-def _init_submodule():
- print(" --- Initializing submodules")
- try:
- subprocess.check_call(["git", "submodule", "init"])
- subprocess.check_call(["git", "submodule", "update"])
- except Exception:
- print(" --- Submodule initalization failed")
- print("Please run:\n\tgit submodule update --init --recursive")
- sys.exit(1)
- print(" --- Initialized submodule")
-
-
def _parse_url(path):
with open(path, "r") as file_:
for line in file_:
@@ -104,18 +91,6 @@ def _parse_url(path):
yield url
-def _parse_sources():
- third_party_dir = ROOT_DIR / "third_party"
- libs = ["sox"]
- archive_dir = third_party_dir / "archives"
- archive_dir.mkdir(exist_ok=True)
- for lib in libs:
- cmake_file = third_party_dir / lib / "CMakeLists.txt"
- for url in _parse_url(cmake_file):
- path = archive_dir / os.path.basename(url)
- yield path, url
-
-
def _fetch_archives(src):
for dest, url in src:
if not dest.exists():
@@ -123,13 +98,6 @@ def _fetch_archives(src):
torch.hub.download_url_to_file(url, dest, progress=False)
-def _fetch_third_party_libraries():
- # Revert this when a submodule is added again
- # _init_submodule()
- if os.name != "nt":
- _fetch_archives(_parse_sources())
-
-
def _main():
sha = _run_cmd(["git", "rev-parse", "HEAD"])
branch = _run_cmd(["git", "rev-parse", "--abbrev-ref", "HEAD"])
@@ -143,7 +111,6 @@ def _main():
print("-- Building version", version)
_make_version_file(version, sha)
- _fetch_third_party_libraries()
with open("README.md") as f:
long_description = f.read()
diff --git a/third_party/sox/CMakeLists.txt b/third_party/sox/CMakeLists.txt
index c4f5dd8931..db96f05faf 100644
--- a/third_party/sox/CMakeLists.txt
+++ b/third_party/sox/CMakeLists.txt
@@ -1,212 +1,21 @@
-find_package(PkgConfig REQUIRED)
+include(FetchContent)
-include(ExternalProject)
-
-set(INSTALL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../install)
-set(ARCHIVE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../archives)
-set(patch_dir ${PROJECT_SOURCE_DIR}/third_party/patches)
-set(COMMON_ARGS --quiet --disable-shared --enable-static --prefix=${INSTALL_DIR} --with-pic --disable-dependency-tracking --disable-debug --disable-examples --disable-doc)
-
-# To pass custom environment variables to ExternalProject_Add command,
-# we need to do `${CMAKE_COMMAND} -E env ${envs} `.
-# https://stackoverflow.com/a/62437353
-# We constrcut the custom environment variables here
-set(envs
- "PKG_CONFIG_PATH=${INSTALL_DIR}/lib/pkgconfig"
- "LDFLAGS=-L${INSTALL_DIR}/lib $ENV{LDFLAGS}"
- "CFLAGS=-I${INSTALL_DIR}/include -fvisibility=hidden $ENV{CFLAGS}"
-)
-
-ExternalProject_Add(amr
- PREFIX ${CMAKE_CURRENT_BINARY_DIR}
- DOWNLOAD_DIR ${ARCHIVE_DIR}
- URL https://sourceforge.net/projects/opencore-amr/files/opencore-amr/opencore-amr-0.1.5.tar.gz
- URL_HASH SHA256=2c006cb9d5f651bfb5e60156dbff6af3c9d35c7bbcc9015308c0aff1e14cd341
- PATCH_COMMAND cp ${patch_dir}/config.guess ${patch_dir}/config.sub ${CMAKE_CURRENT_BINARY_DIR}/src/amr/
- CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env ${envs} ${CMAKE_CURRENT_BINARY_DIR}/src/amr/configure ${COMMON_ARGS}
- DOWNLOAD_NO_PROGRESS ON
- LOG_DOWNLOAD ON
- LOG_UPDATE ON
- LOG_CONFIGURE ON
- LOG_BUILD ON
- LOG_INSTALL ON
- LOG_MERGED_STDOUTERR ON
- LOG_OUTPUT_ON_FAILURE ON
-)
-
-ExternalProject_Add(lame
- PREFIX ${CMAKE_CURRENT_BINARY_DIR}
- DOWNLOAD_DIR ${ARCHIVE_DIR}
- URL https://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz
- URL_HASH SHA256=24346b4158e4af3bd9f2e194bb23eb473c75fb7377011523353196b19b9a23ff
- PATCH_COMMAND cp ${patch_dir}/config.guess ${patch_dir}/config.sub ${CMAKE_CURRENT_BINARY_DIR}/src/lame/
- CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env ${envs} ${CMAKE_CURRENT_BINARY_DIR}/src/lame/configure ${COMMON_ARGS} --enable-nasm
- DOWNLOAD_NO_PROGRESS ON
- LOG_DOWNLOAD ON
- LOG_UPDATE ON
- LOG_CONFIGURE ON
- LOG_BUILD ON
- LOG_INSTALL ON
- LOG_MERGED_STDOUTERR ON
- LOG_OUTPUT_ON_FAILURE ON
-)
-
-ExternalProject_Add(ogg
- PREFIX ${CMAKE_CURRENT_BINARY_DIR}
- DOWNLOAD_DIR ${ARCHIVE_DIR}
- URL https://ftp.osuosl.org/pub/xiph/releases/ogg/libogg-1.3.3.tar.gz
- URL_HASH SHA256=c2e8a485110b97550f453226ec644ebac6cb29d1caef2902c007edab4308d985
- PATCH_COMMAND cp ${patch_dir}/config.guess ${patch_dir}/config.sub ${CMAKE_CURRENT_BINARY_DIR}/src/ogg/
- CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env ${envs} ${CMAKE_CURRENT_BINARY_DIR}/src/ogg/configure ${COMMON_ARGS}
- DOWNLOAD_NO_PROGRESS ON
- LOG_DOWNLOAD ON
- LOG_UPDATE ON
- LOG_CONFIGURE ON
- LOG_BUILD ON
- LOG_INSTALL ON
- LOG_MERGED_STDOUTERR ON
- LOG_OUTPUT_ON_FAILURE ON
-)
-
-ExternalProject_Add(flac
- PREFIX ${CMAKE_CURRENT_BINARY_DIR}
- DEPENDS ogg
- DOWNLOAD_DIR ${ARCHIVE_DIR}
- URL https://ftp.osuosl.org/pub/xiph/releases/flac/flac-1.3.2.tar.xz
- URL_HASH SHA256=91cfc3ed61dc40f47f050a109b08610667d73477af6ef36dcad31c31a4a8d53f
- PATCH_COMMAND cp ${patch_dir}/config.guess ${patch_dir}/config.sub ${CMAKE_CURRENT_BINARY_DIR}/src/flac/
- CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env ${envs} ${CMAKE_CURRENT_BINARY_DIR}/src/flac/configure ${COMMON_ARGS} --with-ogg --disable-cpplibs --disable-xmms-plugin
- DOWNLOAD_NO_PROGRESS ON
- LOG_DOWNLOAD ON
- LOG_UPDATE ON
- LOG_CONFIGURE ON
- LOG_BUILD ON
- LOG_INSTALL ON
- LOG_MERGED_STDOUTERR ON
- LOG_OUTPUT_ON_FAILURE ON
-)
-
-ExternalProject_Add(vorbis
- PREFIX ${CMAKE_CURRENT_BINARY_DIR}
- DEPENDS ogg
- DOWNLOAD_DIR ${ARCHIVE_DIR}
- URL https://ftp.osuosl.org/pub/xiph/releases/vorbis/libvorbis-1.3.6.tar.gz
- URL_HASH SHA256=6ed40e0241089a42c48604dc00e362beee00036af2d8b3f46338031c9e0351cb
- PATCH_COMMAND cp ${patch_dir}/config.guess ${patch_dir}/config.sub ${CMAKE_CURRENT_BINARY_DIR}/src/vorbis/
- CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env ${envs} ${CMAKE_CURRENT_BINARY_DIR}/src/vorbis/configure ${COMMON_ARGS} --with-ogg
- DOWNLOAD_NO_PROGRESS ON
- LOG_DOWNLOAD ON
- LOG_UPDATE ON
- LOG_CONFIGURE ON
- LOG_BUILD ON
- LOG_INSTALL ON
- LOG_MERGED_STDOUTERR ON
- LOG_OUTPUT_ON_FAILURE ON
-)
-
-ExternalProject_Add(opus
- PREFIX ${CMAKE_CURRENT_BINARY_DIR}
- DEPENDS ogg
- DOWNLOAD_DIR ${ARCHIVE_DIR}
- URL https://ftp.osuosl.org/pub/xiph/releases/opus/opus-1.3.1.tar.gz
- URL_HASH SHA256=65b58e1e25b2a114157014736a3d9dfeaad8d41be1c8179866f144a2fb44ff9d
- PATCH_COMMAND cp ${patch_dir}/config.guess ${patch_dir}/config.sub ${CMAKE_CURRENT_BINARY_DIR}/src/opus/
- CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env ${envs} ${CMAKE_CURRENT_BINARY_DIR}/src/opus/configure ${COMMON_ARGS} --with-ogg
- DOWNLOAD_NO_PROGRESS ON
- LOG_DOWNLOAD ON
- LOG_UPDATE ON
- LOG_CONFIGURE ON
- LOG_BUILD ON
- LOG_INSTALL ON
- LOG_MERGED_STDOUTERR ON
- LOG_OUTPUT_ON_FAILURE ON
-)
-
-ExternalProject_Add(opusfile
- PREFIX ${CMAKE_CURRENT_BINARY_DIR}
- DEPENDS opus
- DOWNLOAD_DIR ${ARCHIVE_DIR}
- URL https://ftp.osuosl.org/pub/xiph/releases/opus/opusfile-0.12.tar.gz
- URL_HASH SHA256=118d8601c12dd6a44f52423e68ca9083cc9f2bfe72da7a8c1acb22a80ae3550b
- PATCH_COMMAND cp ${patch_dir}/config.guess ${patch_dir}/config.sub ${CMAKE_CURRENT_BINARY_DIR}/src/opusfile/
- CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env ${envs} ${CMAKE_CURRENT_BINARY_DIR}/src/opusfile/configure ${COMMON_ARGS} --disable-http
- DOWNLOAD_NO_PROGRESS ON
- LOG_DOWNLOAD ON
- LOG_UPDATE ON
- LOG_CONFIGURE ON
- LOG_BUILD ON
- LOG_INSTALL ON
- LOG_MERGED_STDOUTERR ON
- LOG_OUTPUT_ON_FAILURE ON
-)
-
-# OpenMP is by default compiled against GNU OpenMP, which conflicts with the version of OpenMP that PyTorch uses.
-# See https://github.com/pytorch/audio/pull/1026
-# TODO: Add flags like https://github.com/suphoff/pytorch_parallel_extension_cpp/blob/master/setup.py
-set(SOX_OPTIONS
- --disable-openmp
- --with-amrnb
- --with-amrwb
- --with-flac
- --with-lame
- --with-oggvorbis
- --with-opus
- --without-alsa
- --without-ao
- --without-coreaudio
- --without-oss
- --without-id3tag
- --without-ladspa
- --without-mad
- --without-magic
- --without-png
- --without-pulseaudio
- --without-sndfile
- --without-sndio
- --without-sunaudio
- --without-waveaudio
- --without-wavpack
- --without-twolame
- )
-
-set(SOX_LIBRARIES
- ${INSTALL_DIR}/lib/libsox.a
- ${INSTALL_DIR}/lib/libopencore-amrnb.a
- ${INSTALL_DIR}/lib/libopencore-amrwb.a
- ${INSTALL_DIR}/lib/libmp3lame.a
- ${INSTALL_DIR}/lib/libFLAC.a
- ${INSTALL_DIR}/lib/libopusfile.a
- ${INSTALL_DIR}/lib/libopus.a
- ${INSTALL_DIR}/lib/libvorbisenc.a
- ${INSTALL_DIR}/lib/libvorbisfile.a
- ${INSTALL_DIR}/lib/libvorbis.a
- ${INSTALL_DIR}/lib/libogg.a
- )
-
-set(sox_depends
- ogg flac vorbis opusfile lame amr
- )
-
-ExternalProject_Add(sox
- PREFIX ${CMAKE_CURRENT_BINARY_DIR}
- DEPENDS ${sox_depends}
- DOWNLOAD_DIR ${ARCHIVE_DIR}
+FetchContent_Declare(
+ sox_src
URL https://downloads.sourceforge.net/project/sox/sox/14.4.2/sox-14.4.2.tar.bz2
URL_HASH SHA256=81a6956d4330e75b5827316e44ae381e6f1e8928003c6aa45896da9041ea149c
- PATCH_COMMAND cp ${patch_dir}/config.guess ${patch_dir}/config.sub ${CMAKE_CURRENT_BINARY_DIR}/src/sox/
- CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env ${envs} ${CMAKE_CURRENT_BINARY_DIR}/src/sox/configure ${COMMON_ARGS} ${SOX_OPTIONS}
- BUILD_BYPRODUCTS ${SOX_LIBRARIES}
- DOWNLOAD_NO_PROGRESS ON
- LOG_DOWNLOAD ON
- LOG_UPDATE ON
- LOG_CONFIGURE ON
- LOG_BUILD ON
- LOG_INSTALL ON
- LOG_MERGED_STDOUTERR ON
- LOG_OUTPUT_ON_FAILURE ON
-)
-
-add_library(libsox INTERFACE)
-add_dependencies(libsox sox)
-target_include_directories(libsox INTERFACE ${INSTALL_DIR}/include)
-target_link_libraries(libsox INTERFACE ${SOX_LIBRARIES})
+ PATCH_COMMAND ""
+ CONFIGURE_COMMAND ""
+ BUILD_COMMAND ""
+ )
+# FetchContent_MakeAvailable will parse the downloaded content and setup the targets.
+# We want to only download and not build, so we run Populate manually.
+if(NOT sox_src_POPULATED)
+ FetchContent_Populate(sox_src)
+endif()
+
+add_library(sox SHARED stub.c)
+if(APPLE)
+ set_target_properties(sox PROPERTIES SUFFIX .dylib)
+endif(APPLE)
+target_include_directories(sox PUBLIC ${sox_src_SOURCE_DIR}/src)
diff --git a/third_party/sox/stub.c b/third_party/sox/stub.c
new file mode 100644
index 0000000000..4e668caf37
--- /dev/null
+++ b/third_party/sox/stub.c
@@ -0,0 +1,85 @@
+#include
+
+int sox_add_effect(
+ sox_effects_chain_t* chain,
+ sox_effect_t* effp,
+ sox_signalinfo_t* in,
+ sox_signalinfo_t const* out) {
+ return -1;
+}
+int sox_close(sox_format_t* ft) {
+ return -1;
+}
+
+sox_effect_t* sox_create_effect(sox_effect_handler_t const* eh) {
+ return NULL;
+}
+
+sox_effects_chain_t* sox_create_effects_chain(
+ sox_encodinginfo_t const* in_enc,
+ sox_encodinginfo_t const* out_enc) {
+ return NULL;
+}
+
+void sox_delete_effect(sox_effect_t* effp) {}
+void sox_delete_effects_chain(sox_effects_chain_t* ecp) {}
+
+int sox_effect_options(sox_effect_t* effp, int argc, char* const argv[]) {
+ return -1;
+}
+
+const sox_effect_handler_t* sox_find_effect(char const* name) {
+ return NULL;
+}
+
+int sox_flow_effects(
+ sox_effects_chain_t* chain,
+ int callback(sox_bool all_done, void* client_data),
+ void* client_data) {
+ return -1;
+}
+
+const sox_effect_fn_t* sox_get_effect_fns(void) {
+ return NULL;
+}
+
+const sox_format_tab_t* sox_get_format_fns(void) {
+ return NULL;
+}
+
+sox_globals_t* sox_get_globals(void) {
+ return NULL;
+}
+
+sox_format_t* sox_open_read(
+ char const* path,
+ sox_signalinfo_t const* signal,
+ sox_encodinginfo_t const* encoding,
+ char const* filetype) {
+ return NULL;
+}
+
+sox_format_t* sox_open_write(
+ char const* path,
+ sox_signalinfo_t const* signal,
+ sox_encodinginfo_t const* encoding,
+ char const* filetype,
+ sox_oob_t const* oob,
+ sox_bool overwrite_permitted(char const* filename)) {
+ return NULL;
+}
+
+const char* sox_strerror(int sox_errno) {
+ return NULL;
+}
+
+size_t sox_write(sox_format_t* ft, const sox_sample_t* buf, size_t len) {
+ return 0;
+}
+
+int sox_init() {
+ return -1;
+};
+int sox_quit() {
+ return -1;
+};
diff --git a/torchaudio/_extension/__init__.py b/torchaudio/_extension/__init__.py
index 11d99f2df0..2927131704 100644
--- a/torchaudio/_extension/__init__.py
+++ b/torchaudio/_extension/__init__.py
@@ -8,7 +8,7 @@
from .fb import _init_ffmpeg
except ImportError:
from .utils import _init_ffmpeg
-from .utils import _check_cuda_version, _fail_since_no_ffmpeg, _init_dll_path, _init_sox, _load_lib
+from .utils import _check_cuda_version, _fail_since_no_ffmpeg, _fail_since_no_sox, _init_dll_path, _init_sox, _load_lib
_LG = logging.getLogger(__name__)
@@ -51,17 +51,21 @@
_IS_ALIGN_AVAILABLE = torchaudio.lib._torchaudio.is_align_available()
-# Similar to libtorchaudio, sox-related features should be importable when present.
-#
-# Note: This will be change in the future when sox is dynamically linked.
-# At that point, this initialization should handle the case where
-# sox integration is built but libsox is not found.
+# Initialize libsox-related features
_SOX_INITIALIZED = False
_USE_SOX = False if os.name == "nt" else eval_env("TORCHAUDIO_USE_SOX", True)
_SOX_MODULE_AVAILABLE = is_module_available("torchaudio.lib._torchaudio_sox")
if _USE_SOX and _SOX_MODULE_AVAILABLE:
- _init_sox()
- _SOX_INITIALIZED = True
+ try:
+ _init_sox()
+ _SOX_INITIALIZED = True
+ except Exception:
+ # The initialization of sox extension will fail if supported sox
+ # libraries are not found in the system.
+ # Since the rest of the torchaudio works without it, we do not report the
+ # error here.
+ # The error will be raised when user code attempts to use these features.
+ _LG.debug("Failed to initialize sox extension", exc_info=True)
if os.name == "nt":
@@ -74,7 +78,7 @@
"Please build TorchAudio with libsox support. (BUILD_SOX=1)"
)
else:
- fail_if_no_sox = no_op
+ fail_if_no_sox = no_op if _SOX_INITIALIZED else _fail_since_no_sox
# Initialize FFmpeg-related features
diff --git a/torchaudio/_extension/utils.py b/torchaudio/_extension/utils.py
index 2045482cb6..21d4578e01 100644
--- a/torchaudio/_extension/utils.py
+++ b/torchaudio/_extension/utils.py
@@ -197,6 +197,25 @@ def _check_cuda_version():
return version
+def _fail_since_no_sox(func):
+ @wraps(func)
+ def wrapped(*_args, **_kwargs):
+ try:
+ # Note:
+ # We run _init_sox again just to show users the stacktrace.
+ # _init_sox would not succeed here.
+ _init_sox()
+ except Exception as err:
+ raise RuntimeError(
+ f"{func.__name__} requires sox extension which is not available. "
+ "Please refer to the stacktrace above for how to resolve this."
+ ) from err
+ # This should not happen in normal execution, but just in case.
+ return func(*_args, **_kwargs)
+
+ return wrapped
+
+
def _fail_since_no_ffmpeg(func):
@wraps(func)
def wrapped(*_args, **_kwargs):
diff --git a/torchaudio/csrc/sox/CMakeLists.txt b/torchaudio/csrc/sox/CMakeLists.txt
index 3391a4fc37..5ffe782c82 100644
--- a/torchaudio/csrc/sox/CMakeLists.txt
+++ b/torchaudio/csrc/sox/CMakeLists.txt
@@ -10,7 +10,7 @@ torchaudio_library(
libtorchaudio_sox
"${sources}"
""
- "torch;libsox"
+ "torch;sox"
""
)
diff --git a/torchaudio/csrc/sox/utils.h b/torchaudio/csrc/sox/utils.h
index 255d7270fe..b118365999 100644
--- a/torchaudio/csrc/sox/utils.h
+++ b/torchaudio/csrc/sox/utils.h
@@ -2,7 +2,7 @@
#define TORCHAUDIO_SOX_UTILS_H
#include
-#include
+#include
namespace torchaudio::sox {