Skip to content

Commit a5a52c4

Browse files
committed
Add opus support (#755)
1 parent 9c4b4f2 commit a5a52c4

File tree

15 files changed

+131
-36
lines changed

15 files changed

+131
-36
lines changed

.circleci/config.yml

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,13 @@ commands:
3838
our_upload_channel=test
3939
fi
4040
echo "export UPLOAD_CHANNEL=${our_upload_channel}" >> ${BASH_ENV}
41-
install_cmake_macos:
42-
description: "installs cmake on macOS. Use binary distribution as brew is slow"
41+
install_build_tools_macos:
42+
description: "installs tools required to build torchaudio"
4343
steps:
4444
- run:
45-
name: Install cmake
46-
command: |
47-
curl -L -o cmake.tar.gz https://github.com/Kitware/CMake/releases/download/v3.16.5/cmake-3.16.5-Darwin-x86_64.tar.gz
48-
mkdir cmake
49-
tar -xf cmake.tar.gz --strip 3 -C cmake
50-
rm cmake.tar.gz
51-
echo 'export PATH='"${PWD}/cmake/bin"':${PATH}' >> ${BASH_ENV}
45+
name: Install cmake and pkg-config
46+
command: HOMEBREW_NO_AUTO_UPDATE=1 brew install cmake pkg-config
47+
# Disable brew auto update which is very slow
5248

5349
binary_common: &binary_common
5450
parameters:
@@ -158,7 +154,7 @@ jobs:
158154
xcode: "9.0"
159155
steps:
160156
- checkout
161-
- install_cmake_macos
157+
- install_build_tools_macos
162158
- attach_workspace:
163159
at: third_party
164160
- run:
@@ -183,7 +179,7 @@ jobs:
183179
xcode: "9.0"
184180
steps:
185181
- checkout
186-
- install_cmake_macos
182+
- install_build_tools_macos
187183
- attach_workspace:
188184
at: third_party
189185
- run:
@@ -398,14 +394,14 @@ jobs:
398394
- restore_cache:
399395

400396
keys:
401-
- env-v3-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum ".cachekey" }}
397+
- env-v3-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum "third_party/CMakeLists.txt" }}-{{ checksum ".cachekey" }}
402398

403399
- run:
404400
name: Setup
405401
command: .circleci/unittest/linux/scripts/setup_env.sh
406402
- save_cache:
407403

408-
key: env-v3-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum ".cachekey" }}
404+
key: env-v3-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum "third_party/CMakeLists.txt" }}-{{ checksum ".cachekey" }}
409405

410406
paths:
411407
- conda
@@ -440,14 +436,14 @@ jobs:
440436
- restore_cache:
441437

442438
keys:
443-
- env-v3-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum ".cachekey" }}
439+
- env-v3-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum "third_party/CMakeLists.txt" }}-{{ checksum ".cachekey" }}
444440

445441
- run:
446442
name: Setup
447443
command: docker run -t --gpus all -v $PWD:$PWD -w $PWD "${image_name}" .circleci/unittest/linux/scripts/setup_env.sh
448444
- save_cache:
449445

450-
key: env-v3-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum ".cachekey" }}
446+
key: env-v3-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum "third_party/CMakeLists.txt" }}-{{ checksum ".cachekey" }}
451447

452448
paths:
453449
- conda

.circleci/config.yml.in

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,13 @@ commands:
3838
our_upload_channel=test
3939
fi
4040
echo "export UPLOAD_CHANNEL=${our_upload_channel}" >> ${BASH_ENV}
41-
install_cmake_macos:
42-
description: "installs cmake on macOS. Use binary distribution as brew is slow"
41+
install_build_tools_macos:
42+
description: "installs tools required to build torchaudio"
4343
steps:
4444
- run:
45-
name: Install cmake
46-
command: |
47-
curl -L -o cmake.tar.gz https://github.com/Kitware/CMake/releases/download/v3.16.5/cmake-3.16.5-Darwin-x86_64.tar.gz
48-
mkdir cmake
49-
tar -xf cmake.tar.gz --strip 3 -C cmake
50-
rm cmake.tar.gz
51-
echo 'export PATH='"${PWD}/cmake/bin"':${PATH}' >> ${BASH_ENV}
45+
name: Install cmake and pkg-config
46+
command: HOMEBREW_NO_AUTO_UPDATE=1 brew install cmake pkg-config
47+
# Disable brew auto update which is very slow
5248

5349
binary_common: &binary_common
5450
parameters:
@@ -158,7 +154,7 @@ jobs:
158154
xcode: "9.0"
159155
steps:
160156
- checkout
161-
- install_cmake_macos
157+
- install_build_tools_macos
162158
- attach_workspace:
163159
at: third_party
164160
- run:
@@ -183,7 +179,7 @@ jobs:
183179
xcode: "9.0"
184180
steps:
185181
- checkout
186-
- install_cmake_macos
182+
- install_build_tools_macos
187183
- attach_workspace:
188184
at: third_party
189185
- run:
@@ -398,14 +394,14 @@ jobs:
398394
- restore_cache:
399395
{% raw %}
400396
keys:
401-
- env-v3-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum ".cachekey" }}
397+
- env-v3-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum "third_party/CMakeLists.txt" }}-{{ checksum ".cachekey" }}
402398
{% endraw %}
403399
- run:
404400
name: Setup
405401
command: .circleci/unittest/linux/scripts/setup_env.sh
406402
- save_cache:
407403
{% raw %}
408-
key: env-v3-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum ".cachekey" }}
404+
key: env-v3-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum "third_party/CMakeLists.txt" }}-{{ checksum ".cachekey" }}
409405
{% endraw %}
410406
paths:
411407
- conda
@@ -440,14 +436,14 @@ jobs:
440436
- restore_cache:
441437
{% raw %}
442438
keys:
443-
- env-v3-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum ".cachekey" }}
439+
- env-v3-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum "third_party/CMakeLists.txt" }}-{{ checksum ".cachekey" }}
444440
{% endraw %}
445441
- run:
446442
name: Setup
447443
command: docker run -t --gpus all -v $PWD:$PWD -w $PWD "${image_name}" .circleci/unittest/linux/scripts/setup_env.sh
448444
- save_cache:
449445
{% raw %}
450-
key: env-v3-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum ".cachekey" }}
446+
key: env-v3-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum "third_party/CMakeLists.txt" }}-{{ checksum ".cachekey" }}
451447
{% endraw %}
452448
paths:
453449
- conda

.circleci/unittest/linux/docker/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ RUN apt update && apt install -y \
5959
libsox-dev \
6060
libsox-fmt-all \
6161
cmake \
62+
pkg-config \
6263
&& rm -rf /var/lib/apt/lists/*
6364
COPY --from=builder /kaldi /kaldi
6465
COPY --from=builder /third_party /third_party

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ python setup.py install
113113
MACOSX_DEPLOYMENT_TARGET=10.9 CC=clang CXX=clang++ python setup.py install
114114
```
115115

116-
Alternatively, the build process can build SoX (and codecs such as libmad, lame and flac) statically and torchaudio can link them, by setting environment variable `BUILD_SOX=1`.
117-
The build process will fetch and build SoX, liblame, libmad, flac before building extension.
116+
Alternatively, the build process can build libsox and some optional codecs statically and torchaudio can link them, by setting environment variable `BUILD_SOX=1`.
117+
The build process will fetch and build libmad, lame, flac, vorbis, opus, and libsox before building extension. This process requires `cmake` and `pkg-config`.
118118

119119
```bash
120120
# Linux

build_tools/setup_helpers/extension.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ def _get_extra_objects():
8383
'libmad.a',
8484
'libFLAC.a',
8585
'libmp3lame.a',
86+
'libopusfile.a',
87+
'libopus.a',
8688
'libvorbisenc.a',
8789
'libvorbisfile.a',
8890
'libvorbis.a',

test/assets/io/96k_0_1ch.opus

8.07 KB
Binary file not shown.

test/assets/io/96k_0_2ch.opus

6.58 KB
Binary file not shown.

test/assets/io/96k_10_1ch.opus

14.7 KB
Binary file not shown.

test/assets/io/96k_10_2ch.opus

14.8 KB
Binary file not shown.

test/assets/io/96k_5_1ch.opus

12.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)