Code Monkey home page Code Monkey logo

audio's Introduction

PyTorch Logo


PyTorch is a Python package that provides two high-level features:

  • Tensor computation (like NumPy) with strong GPU acceleration
  • Deep neural networks built on a tape-based autograd system

You can reuse your favorite Python packages such as NumPy, SciPy, and Cython to extend PyTorch when needed.

Our trunk health (Continuous Integration signals) can be found at hud.pytorch.org.

More About PyTorch

Learn the basics of PyTorch

At a granular level, PyTorch is a library that consists of the following components:

Component Description
torch A Tensor library like NumPy, with strong GPU support
torch.autograd A tape-based automatic differentiation library that supports all differentiable Tensor operations in torch
torch.jit A compilation stack (TorchScript) to create serializable and optimizable models from PyTorch code
torch.nn A neural networks library deeply integrated with autograd designed for maximum flexibility
torch.multiprocessing Python multiprocessing, but with magical memory sharing of torch Tensors across processes. Useful for data loading and Hogwild training
torch.utils DataLoader and other utility functions for convenience

Usually, PyTorch is used either as:

  • A replacement for NumPy to use the power of GPUs.
  • A deep learning research platform that provides maximum flexibility and speed.

Elaborating Further:

A GPU-Ready Tensor Library

If you use NumPy, then you have used Tensors (a.k.a. ndarray).

Tensor illustration

PyTorch provides Tensors that can live either on the CPU or the GPU and accelerates the computation by a huge amount.

We provide a wide variety of tensor routines to accelerate and fit your scientific computation needs such as slicing, indexing, mathematical operations, linear algebra, reductions. And they are fast!

Dynamic Neural Networks: Tape-Based Autograd

PyTorch has a unique way of building neural networks: using and replaying a tape recorder.

Most frameworks such as TensorFlow, Theano, Caffe, and CNTK have a static view of the world. One has to build a neural network and reuse the same structure again and again. Changing the way the network behaves means that one has to start from scratch.

With PyTorch, we use a technique called reverse-mode auto-differentiation, which allows you to change the way your network behaves arbitrarily with zero lag or overhead. Our inspiration comes from several research papers on this topic, as well as current and past work such as torch-autograd, autograd, Chainer, etc.

While this technique is not unique to PyTorch, it's one of the fastest implementations of it to date. You get the best of speed and flexibility for your crazy research.

Dynamic graph

Python First

PyTorch is not a Python binding into a monolithic C++ framework. It is built to be deeply integrated into Python. You can use it naturally like you would use NumPy / SciPy / scikit-learn etc. You can write your new neural network layers in Python itself, using your favorite libraries and use packages such as Cython and Numba. Our goal is to not reinvent the wheel where appropriate.

Imperative Experiences

PyTorch is designed to be intuitive, linear in thought, and easy to use. When you execute a line of code, it gets executed. There isn't an asynchronous view of the world. When you drop into a debugger or receive error messages and stack traces, understanding them is straightforward. The stack trace points to exactly where your code was defined. We hope you never spend hours debugging your code because of bad stack traces or asynchronous and opaque execution engines.

Fast and Lean

PyTorch has minimal framework overhead. We integrate acceleration libraries such as Intel MKL and NVIDIA (cuDNN, NCCL) to maximize speed. At the core, its CPU and GPU Tensor and neural network backends are mature and have been tested for years.

Hence, PyTorch is quite fast — whether you run small or large neural networks.

The memory usage in PyTorch is extremely efficient compared to Torch or some of the alternatives. We've written custom memory allocators for the GPU to make sure that your deep learning models are maximally memory efficient. This enables you to train bigger deep learning models than before.

Extensions Without Pain

Writing new neural network modules, or interfacing with PyTorch's Tensor API was designed to be straightforward and with minimal abstractions.

You can write new neural network layers in Python using the torch API or your favorite NumPy-based libraries such as SciPy.

If you want to write your layers in C/C++, we provide a convenient extension API that is efficient and with minimal boilerplate. No wrapper code needs to be written. You can see a tutorial here and an example here.

Installation

Binaries

Commands to install binaries via Conda or pip wheels are on our website: https://pytorch.org/get-started/locally/

NVIDIA Jetson Platforms

Python wheels for NVIDIA's Jetson Nano, Jetson TX1/TX2, Jetson Xavier NX/AGX, and Jetson AGX Orin are provided here and the L4T container is published here

They require JetPack 4.2 and above, and @dusty-nv and @ptrblck are maintaining them.

From Source

Prerequisites

If you are installing from source, you will need:

  • Python 3.8 or later (for Linux, Python 3.8.1+ is needed)
  • A compiler that fully supports C++17, such as clang or gcc (gcc 9.4.0 or newer is required)

We highly recommend installing an Anaconda environment. You will get a high-quality BLAS library (MKL) and you get controlled dependency versions regardless of your Linux distro.

NVIDIA CUDA Support

If you want to compile with CUDA support, select a supported version of CUDA from our support matrix, then install the following:

Note: You could refer to the cuDNN Support Matrix for cuDNN versions with the various supported CUDA, CUDA driver and NVIDIA hardware

If you want to disable CUDA support, export the environment variable USE_CUDA=0. Other potentially useful environment variables may be found in setup.py.

If you are building for NVIDIA's Jetson platforms (Jetson Nano, TX1, TX2, AGX Xavier), Instructions to install PyTorch for Jetson Nano are available here

AMD ROCm Support

If you want to compile with ROCm support, install

  • AMD ROCm 4.0 and above installation
  • ROCm is currently supported only for Linux systems.

If you want to disable ROCm support, export the environment variable USE_ROCM=0. Other potentially useful environment variables may be found in setup.py.

Intel GPU Support

If you want to compile with Intel GPU support, follow these

If you want to disable Intel GPU support, export the environment variable USE_XPU=0. Other potentially useful environment variables may be found in setup.py.

Install Dependencies

Common

conda install cmake ninja
# Run this command from the PyTorch directory after cloning the source code using the “Get the PyTorch Source“ section below
pip install -r requirements.txt

On Linux

conda install intel::mkl-static intel::mkl-include
# CUDA only: Add LAPACK support for the GPU if needed
conda install -c pytorch magma-cuda121  # or the magma-cuda* that matches your CUDA version from https://anaconda.org/pytorch/repo

# (optional) If using torch.compile with inductor/triton, install the matching version of triton
# Run from the pytorch directory after cloning
make triton

On MacOS

# Add this package on intel x86 processor machines only
conda install intel::mkl-static intel::mkl-include
# Add these packages if torch.distributed is needed
conda install pkg-config libuv

On Windows

conda install intel::mkl-static intel::mkl-include
# Add these packages if torch.distributed is needed.
# Distributed package support on Windows is a prototype feature and is subject to changes.
conda install -c conda-forge libuv=1.39

Get the PyTorch Source

git clone --recursive https://github.com/pytorch/pytorch
cd pytorch
# if you are updating an existing checkout
git submodule sync
git submodule update --init --recursive

Install PyTorch

On Linux

If you would like to compile PyTorch with new C++ ABI enabled, then first run this command:

export _GLIBCXX_USE_CXX11_ABI=1

If you're compiling for AMD ROCm then first run this command:

# Only run this if you're compiling for ROCm
python tools/amd_build/build_amd.py

Install PyTorch

export CMAKE_PREFIX_PATH=${CONDA_PREFIX:-"$(dirname $(which conda))/../"}
python setup.py develop

Aside: If you are using Anaconda, you may experience an error caused by the linker:

build/temp.linux-x86_64-3.7/torch/csrc/stub.o: file not recognized: file format not recognized
collect2: error: ld returned 1 exit status
error: command 'g++' failed with exit status 1

This is caused by ld from the Conda environment shadowing the system ld. You should use a newer version of Python that fixes this issue. The recommended Python version is 3.8.1+.

On macOS

python3 setup.py develop

On Windows

Choose Correct Visual Studio Version.

PyTorch CI uses Visual C++ BuildTools, which come with Visual Studio Enterprise, Professional, or Community Editions. You can also install the build tools from https://visualstudio.microsoft.com/visual-cpp-build-tools/. The build tools do not come with Visual Studio Code by default.

If you want to build legacy python code, please refer to Building on legacy code and CUDA

CPU-only builds

In this mode PyTorch computations will run on your CPU, not your GPU

conda activate
python setup.py develop

Note on OpenMP: The desired OpenMP implementation is Intel OpenMP (iomp). In order to link against iomp, you'll need to manually download the library and set up the building environment by tweaking CMAKE_INCLUDE_PATH and LIB. The instruction here is an example for setting up both MKL and Intel OpenMP. Without these configurations for CMake, Microsoft Visual C OpenMP runtime (vcomp) will be used.

CUDA based build

In this mode PyTorch computations will leverage your GPU via CUDA for faster number crunching

NVTX is needed to build Pytorch with CUDA. NVTX is a part of CUDA distributive, where it is called "Nsight Compute". To install it onto an already installed CUDA run CUDA installation once again and check the corresponding checkbox. Make sure that CUDA with Nsight Compute is installed after Visual Studio.

Currently, VS 2017 / 2019, and Ninja are supported as the generator of CMake. If ninja.exe is detected in PATH, then Ninja will be used as the default generator, otherwise, it will use VS 2017 / 2019.
If Ninja is selected as the generator, the latest MSVC will get selected as the underlying toolchain.

Additional libraries such as Magma, oneDNN, a.k.a. MKLDNN or DNNL, and Sccache are often needed. Please refer to the installation-helper to install them.

You can refer to the build_pytorch.bat script for some other environment variables configurations

cmd

:: Set the environment variables after you have downloaded and unzipped the mkl package,
:: else CMake would throw an error as `Could NOT find OpenMP`.
set CMAKE_INCLUDE_PATH={Your directory}\mkl\include
set LIB={Your directory}\mkl\lib;%LIB%

:: Read the content in the previous section carefully before you proceed.
:: [Optional] If you want to override the underlying toolset used by Ninja and Visual Studio with CUDA, please run the following script block.
:: "Visual Studio 2019 Developer Command Prompt" will be run automatically.
:: Make sure you have CMake >= 3.12 before you do this when you use the Visual Studio generator.
set CMAKE_GENERATOR_TOOLSET_VERSION=14.27
set DISTUTILS_USE_SDK=1
for /f "usebackq tokens=*" %i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -version [15^,17^) -products * -latest -property installationPath`) do call "%i\VC\Auxiliary\Build\vcvarsall.bat" x64 -vcvars_ver=%CMAKE_GENERATOR_TOOLSET_VERSION%

:: [Optional] If you want to override the CUDA host compiler
set CUDAHOSTCXX=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\bin\HostX64\x64\cl.exe

python setup.py develop
Adjust Build Options (Optional)

You can adjust the configuration of cmake variables optionally (without building first), by doing the following. For example, adjusting the pre-detected directories for CuDNN or BLAS can be done with such a step.

On Linux

export CMAKE_PREFIX_PATH=${CONDA_PREFIX:-"$(dirname $(which conda))/../"}
python setup.py build --cmake-only
ccmake build  # or cmake-gui build

On macOS

export CMAKE_PREFIX_PATH=${CONDA_PREFIX:-"$(dirname $(which conda))/../"}
MACOSX_DEPLOYMENT_TARGET=10.9 CC=clang CXX=clang++ python setup.py build --cmake-only
ccmake build  # or cmake-gui build

Docker Image

Using pre-built images

You can also pull a pre-built docker image from Docker Hub and run with docker v19.03+

docker run --gpus all --rm -ti --ipc=host pytorch/pytorch:latest

Please note that PyTorch uses shared memory to share data between processes, so if torch multiprocessing is used (e.g. for multithreaded data loaders) the default shared memory segment size that container runs with is not enough, and you should increase shared memory size either with --ipc=host or --shm-size command line options to nvidia-docker run.

Building the image yourself

NOTE: Must be built with a docker version > 18.06

The Dockerfile is supplied to build images with CUDA 11.1 support and cuDNN v8. You can pass PYTHON_VERSION=x.y make variable to specify which Python version is to be used by Miniconda, or leave it unset to use the default.

make -f docker.Makefile
# images are tagged as docker.io/${your_docker_username}/pytorch

You can also pass the CMAKE_VARS="..." environment variable to specify additional CMake variables to be passed to CMake during the build. See setup.py for the list of available variables.

make -f docker.Makefile

Building the Documentation

To build documentation in various formats, you will need Sphinx and the readthedocs theme.

cd docs/
pip install -r requirements.txt

You can then build the documentation by running make <format> from the docs/ folder. Run make to get a list of all available output formats.

If you get a katex error run npm install katex. If it persists, try npm install -g katex

Note: if you installed nodejs with a different package manager (e.g., conda) then npm will probably install a version of katex that is not compatible with your version of nodejs and doc builds will fail. A combination of versions that is known to work is [email protected] and [email protected]. To install the latter with npm you can run npm install -g [email protected]

Previous Versions

Installation instructions and binaries for previous PyTorch versions may be found on our website.

Getting Started

Three-pointers to get you started:

Resources

Communication

Releases and Contributing

Typically, PyTorch has three minor releases a year. Please let us know if you encounter a bug by filing an issue.

We appreciate all contributions. If you are planning to contribute back bug-fixes, please do so without any further discussion.

If you plan to contribute new features, utility functions, or extensions to the core, please first open an issue and discuss the feature with us. Sending a PR without discussion might end up resulting in a rejected PR because we might be taking the core in a different direction than you might be aware of.

To learn more about making a contribution to Pytorch, please see our Contribution page. For more information about PyTorch releases, see Release page.

The Team

PyTorch is a community-driven project with several skillful engineers and researchers contributing to it.

PyTorch is currently maintained by Soumith Chintala, Gregory Chanan, Dmytro Dzhulgakov, Edward Yang, and Nikita Shulga with major contributions coming from hundreds of talented individuals in various forms and means. A non-exhaustive but growing list needs to mention: Trevor Killeen, Sasank Chilamkurthy, Sergey Zagoruyko, Adam Lerer, Francisco Massa, Alykhan Tejani, Luca Antiga, Alban Desmaison, Andreas Koepf, James Bradbury, Zeming Lin, Yuandong Tian, Guillaume Lample, Marat Dukhan, Natalia Gimelshein, Christian Sarofeen, Martin Raison, Edward Yang, Zachary Devito.

Note: This project is unrelated to hughperkins/pytorch with the same name. Hugh is a valuable contributor to the Torch community and has helped with many things Torch and PyTorch.

License

PyTorch has a BSD-style license, as found in the LICENSE file.

audio's People

Contributors

atalman avatar azizcode92 avatar bhargavkathivarapu avatar dhpollack avatar engineerchuan avatar ezyang avatar hwangjeff avatar jamarshon avatar jcaw avatar jdsgomes avatar jimchen90 avatar krishnakalyan3 avatar malfet avatar mattip avatar moto-meta avatar mpc001 avatar mszhanyi avatar mthrok avatar nateanl avatar nicolashug avatar osalpekar avatar prabhat00155 avatar ravicodelabs avatar seemethere avatar soumith avatar tomassosorio avatar vincentqb avatar xiaohui-zhang avatar yangarbiter avatar yoyololicon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

audio's Issues

Can't compile on Windows (MinGW)

I tried installing torchaudio with the command python setup.py install using the MinGW64 gcc compiler and got this error:

running install
running bdist_egg
running egg_info
writing torchaudio.egg-info\PKG-INFO
writing dependency_links to torchaudio.egg-info\dependency_links.txt
writing requirements to torchaudio.egg-info\requires.txt
writing top-level names to torchaudio.egg-info\top_level.txt
reading manifest file 'torchaudio.egg-info\SOURCES.txt'
writing manifest file 'torchaudio.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
running build_py
copying torchaudio\_ext\th_sox\__init__.py -> build\lib.win-amd64-3.6\torchaudio\_ext\th_sox
running build_ext
generating cffi module 'build\\temp.win-amd64-3.6\\Release\\torchaudio._ext.th_sox._th_sox.c'
already up-to-date
building 'torchaudio._ext.th_sox._th_sox' extension
C:\Program Files\mingw-w64\x86_64-7.3.0-win32-seh-rt_v5-rev0\mingw64\bin\gcc.exe -mdll -O -Wall -DMS_WIN64 -IC:\Users\n15hugr\AppData\Local\Continuum\miniconda3\lib\site-packages\torch\utils\ffi\..\..\lib\include -IC:\Users\n15hugr\AppData\Local\Continuum\miniconda3\lib\site-packages\torch\utils\ffi\..\..\lib\include\TH -Itorchaudio/src -IC:\Users\n15hugr\AppData\Local\Continuum\miniconda3\include -IC:\Users\n15hugr\AppData\Local\Continuum\miniconda3\include -c build\temp.win-amd64-3.6\Release\torchaudio._ext.th_sox._th_sox.c -o build\temp.win-amd64-3.6\Release\build\temp.win-amd64-3.6\release\torchaudio._ext.th_sox._th_sox.o
C:\Program Files\mingw-w64\x86_64-7.3.0-win32-seh-rt_v5-rev0\mingw64\bin\gcc.exe -mdll -O -Wall -DMS_WIN64 -IC:\Users\n15hugr\AppData\Local\Continuum\miniconda3\lib\site-packages\torch\utils\ffi\..\..\lib\include -IC:\Users\n15hugr\AppData\Local\Continuum\miniconda3\lib\site-packages\torch\utils\ffi\..\..\lib\include\TH -Itorchaudio/src -IC:\Users\n15hugr\AppData\Local\Continuum\miniconda3\include -IC:\Users\n15hugr\AppData\Local\Continuum\miniconda3\include -c C:\Users\n15hugr\Documents\code\audio-master\torchaudio/src/th_sox.c -o c:\users\n15hugr\documents\code\audio-master\torchaudio\src\th_sox.o
writing build\temp.win-amd64-3.6\Release\build\temp.win-amd64-3.6\release\_th_sox.cp36-win_amd64.def
C:\Program Files\mingw-w64\x86_64-7.3.0-win32-seh-rt_v5-rev0\mingw64\bin\gcc.exe -shared -s build\temp.win-amd64-3.6\Release\build\temp.win-amd64-3.6\release\torchaudio._ext.th_sox._th_sox.o c:\users\n15hugr\documents\code\audio-master\torchaudio\src\th_sox.o build\temp.win-amd64-3.6\Release\build\temp.win-amd64-3.6\release\_th_sox.cp36-win_amd64.def -LC:\Users\n15hugr\AppData\Local\Continuum\miniconda3\lib\site-packages\torch\utils\ffi\..\..\lib -LC:\Users\n15hugr\AppData\Local\Continuum\miniconda3\libs -LC:\Users\n15hugr\AppData\Local\Continuum\miniconda3\PCbuild\amd64 -lsox -lpython36 -lmsvcr140 -o build\lib.win-amd64-3.6\torchaudio\_ext\th_sox\_th_sox.cp36-win_amd64.pyd
c:\users\n15hugr\documents\code\audio-master\torchaudio\src\th_sox.o:th_sox.c:(.text+0x0): multiple definition of `log1p'
build\temp.win-amd64-3.6\Release\build\temp.win-amd64-3.6\release\torchaudio._ext.th_sox._th_sox.o:torchaudio._ext.th_sox._th_sox.c:(.text+0x2e83): first defined here
c:\users\n15hugr\documents\code\audio-master\torchaudio\src\th_sox.o:th_sox.c:(.text+0xf): multiple definition of `log2'
build\temp.win-amd64-3.6\Release\build\temp.win-amd64-3.6\release\torchaudio._ext.th_sox._th_sox.o:torchaudio._ext.th_sox._th_sox.c:(.text+0x2e92): first defined here
c:\users\n15hugr\documents\code\audio-master\torchaudio\src\th_sox.o:th_sox.c:(.text+0x1e): multiple definition of `expm1'
build\temp.win-amd64-3.6\Release\build\temp.win-amd64-3.6\release\torchaudio._ext.th_sox._th_sox.o:torchaudio._ext.th_sox._th_sox.c:(.text+0x2ea1): first defined here
C:/Program Files/mingw-w64/x86_64-7.3.0-win32-seh-rt_v5-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lsox
C:/Program Files/mingw-w64/x86_64-7.3.0-win32-seh-rt_v5-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lmsvcr140
collect2.exe: error: ld returned 1 exit status
error: command 'C:\\Program Files\\mingw-w64\\x86_64-7.3.0-win32-seh-rt_v5-rev0\\mingw64\\bin\\gcc.exe' failed with exit status 1

Music Information Retrieval Evaluation Exchange (MIREX) datasets

Each year the Music Information Retrieval Evaluation Exchange (MIREX) sponsors a number of noteworthy competitions for problems like chord, key change, and tempo estimation. Many of the competitions have longstanding (sometimes 10+ years) training and test sets. If torchaudio provided these datasets in a standard format (similar to VCTK or something like PASCAL from torchvision), PyTorch would become an invaluable toolkit for researchers working on these types of problems.

can not import torchaudio

Hi,
I am trying to use torchaudio on Ubuntu and get the following exception:
lib/python3.7/site-packages/torchaudio-0.1-py3.7-linux-x86_64.egg/_torch_sox.cpython-37m-x86_64-linux-gnu.so: undefined symbol: _ZN2at5ErrorC1ENS_14SourceLocationENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE

ldd the so ,get the following:
ldd _torch_sox.cpython-37m-x86_64-linux-gnu.so linux-vdso.so.1 (0x00007ffeccdb2000) libsox.so.3 => /usr/lib/x86_64-linux-gnu/libsox.so.3 (0x00007f9d99960000) libstdc++.so.6 => /home/uname/.conda/envs/PyTorch/lib/libstdc++.so.6 (0x00007f9d99c93000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f9d995c2000) libgcc_s.so.1 => /home/uname/.conda/envs/PyTorch/lib/libgcc_s.so.1 (0x00007f9d99c7e000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f9d993a3000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f9d98fb2000) libltdl.so.7 => /usr/lib/x86_64-linux-gnu/libltdl.so.7 (0x00007f9d98da8000) libpng16.so.16 => /usr/lib/x86_64-linux-gnu/libpng16.so.16 (0x00007f9d98b76000) libz.so.1 => /home/uname/.conda/envs/PyTorch/lib/libz.so.1 (0x00007f9d9895f000) libmagic.so.1 => /usr/lib/x86_64-linux-gnu/libmagic.so.1 (0x00007f9d9873d000) libgsm.so.1 => /usr/lib/x86_64-linux-gnu/libgsm.so.1 (0x00007f9d98530000) libgomp.so.1 => /home/uname/.conda/envs/PyTorch/lib/libgomp.so.1 (0x00007f9d99c56000) /lib64/ld-linux-x86-64.so.2 (0x00007f9d99be8000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f9d9832c000) librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f9d98124000)

objdump the so ,get the following:

objdump -tT _torch_sox.cpython-37m-x86_64-linux-gnu.so | grep _ZN2at5Error
0000000000009850 w F .text 0000000000000047 _ZN2at5ErrorD0Ev
0000000000000000 UND 0000000000000000 _ZN2at5ErrorC1ENS_14SourceLocationENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
0000000000009510 w F .text 000000000000003f _ZN2at5ErrorD1Ev
0000000000009510 w F .text 000000000000003f _ZN2at5ErrorD2Ev
0000000000000000 D UND 0000000000000000 _ZN2at5ErrorC1ENS_14SourceLocationENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
0000000000009510 w DF .text 000000000000003f Base _ZN2at5ErrorD1Ev
0000000000009510 w DF .text 000000000000003f Base _ZN2at5ErrorD2Ev
0000000000009850 w DF .text 0000000000000047 Base _ZN2at5ErrorD0Ev

python setup.py install failed

running install
running bdist_egg
running egg_info
writing torchaudio.egg-info/PKG-INFO
writing top-level names to torchaudio.egg-info/top_level.txt
writing dependency_links to torchaudio.egg-info/dependency_links.txt
reading manifest file 'torchaudio.egg-info/SOURCES.txt'
writing manifest file 'torchaudio.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
running build_ext
/home/rajeev/environments/speech/local/lib/python2.7/site-packages/torch/utils/cpp_extension.py:118: UserWarning:

                           !! WARNING !!

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Your compiler (c++) may be ABI-incompatible with PyTorch!
Please use a compiler that is ABI-compatible with GCC 4.9 and above.
See https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html.

See https://gist.github.com/goldsborough/d466f43e8ffc948ff92de7486c5216d6
for instructions on how to install GCC 4.9 or higher.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

                          !! WARNING !!

warnings.warn(ABI_INCOMPATIBILITY_WARNING.format(compiler))
building '_torch_sox' extension
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/home/rajeev/environments/speech/local/lib/python2.7/site-packages/torch/lib/include -I/home/rajeev/environments/speech/local/lib/python2.7/site-packages/torch/lib/include/TH -I/home/rajeev/environments/speech/local/lib/python2.7/site-packages/torch/lib/include/THC -I/usr/include/python2.7 -c torchaudio/torch_sox.cpp -o build/temp.linux-x86_64-2.7/torchaudio/torch_sox.o -DTORCH_EXTENSION_NAME=_torch_sox -D_GLIBCXX_USE_CXX11_ABI=0 -std=c++11
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
torchaudio/torch_sox.cpp:1:29: fatal error: torch/extension.h: No such file or directory
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

It says fatal error: torch/extension.h: No such file or directory, any idea how to fix this?

reduce aliasing in downsampling

Currently the VCTK dataset loader does implement downsampling without low-pass filtering (=decimation). This results in severe aliasing artifacts and should be avoided.

I would propose to add resampy as a dependency and include this in the base modules so that dataset loaders can utilize a high quality resampling.

I can compile a PR if you like this proposal

Weird build warning about ABI compatibility

Hi there,

when trying to build torchaudio from a Dockerfile, I obtain this warning, I suspect it to provoke pip installation failures afterwards. How can I fix it ?
At a first glance the installed versions of gcc and libstdc++ are correct.

François

Step 11/15 : RUN git clone --recursive https://github.com/pytorch/audio.git
---> Running in 1c0152e3a375
Cloning into 'audio'...
Removing intermediate container 1c0152e3a375
---> 1e796407307e
Step 12/15 : RUN cd audio; python setup.py install
---> Running in ffaec8803f4a
running install
running bdist_egg
running egg_info
creating torchaudio.egg-info
writing torchaudio.egg-info/PKG-INFO
writing top-level names to torchaudio.egg-info/top_level.txt
writing dependency_links to torchaudio.egg-info/dependency_links.txt
writing manifest file 'torchaudio.egg-info/SOURCES.txt'
reading manifest file 'torchaudio.egg-info/SOURCES.txt'
writing manifest file 'torchaudio.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
creating build
creating build/lib.linux-x86_64-2.7
creating build/lib.linux-x86_64-2.7/torchaudio
copying torchaudio/transforms.py -> build/lib.linux-x86_64-2.7/torchaudio
copying torchaudio/init.py -> build/lib.linux-x86_64-2.7/torchaudio
creating build/lib.linux-x86_64-2.7/torchaudio/datasets
copying torchaudio/datasets/init.py -> build/lib.linux-x86_64-2.7/torchaudio/datasets
copying torchaudio/datasets/yesno.py -> build/lib.linux-x86_64-2.7/torchaudio/datasets
copying torchaudio/datasets/vctk.py -> build/lib.linux-x86_64-2.7/torchaudio/datasets
running build_ext
/usr/local/lib/python2.7/dist-packages/torch/utils/cpp_extension.py:118: UserWarning:

                           !! WARNING !!

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Your compiler (c++) may be ABI-incompatible with PyTorch!
Please use a compiler that is ABI-compatible with GCC 4.9 and above.
See https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html.

See https://gist.github.com/goldsborough/d466f43e8ffc948ff92de7486c5216d6
for instructions on how to install GCC 4.9 or higher.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

                          !! WARNING !!

warnings.warn(ABI_INCOMPATIBILITY_WARNING.format(compiler))
building '_torch_sox' extension
creating build/temp.linux-x86_64-2.7
creating build/temp.linux-x86_64-2.7/torchaudio
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/local/lib/python2.7/dist-packages/torch/lib/include -I/usr/local/lib/python2.7/dist-packages/torch/lib/include/TH -I/usr/local/lib/python2.7/dist-packages/torch/lib/include/THC -I/usr/include/python2.7 -c torchaudio/torch_sox.cpp -o build/temp.linux-x86_64-2.7/torchaudio/torch_sox.o -DTORCH_EXTENSION_NAME=_torch_sox -D_GLIBCXX_USE_CXX11_ABI=0 -std=c++11
cc1plus: warning: command line option '-Wstrict-prototypes' is valid for C/ObjC but not for C++
c++ -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wl,-Bsymbolic-functions -Wl,-z,relro -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/torchaudio/torch_sox.o -lsox -o build/lib.linux-x86_64-2.7/_torch_sox.so
creating build/bdist.linux-x86_64
creating build/bdist.linux-x86_64/egg
copying build/lib.linux-x86_64-2.7/_torch_sox.so -> build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/torchaudio
copying build/lib.linux-x86_64-2.7/torchaudio/transforms.py -> build/bdist.linux-x86_64/egg/torchaudio
copying build/lib.linux-x86_64-2.7/torchaudio/init.py -> build/bdist.linux-x86_64/egg/torchaudio
creating build/bdist.linux-x86_64/egg/torchaudio/datasets
copying build/lib.linux-x86_64-2.7/torchaudio/datasets/init.py -> build/bdist.linux-x86_64/egg/torchaudio/datasets
copying build/lib.linux-x86_64-2.7/torchaudio/datasets/yesno.py -> build/bdist.linux-x86_64/egg/torchaudio/datasets
copying build/lib.linux-x86_64-2.7/torchaudio/datasets/vctk.py -> build/bdist.linux-x86_64/egg/torchaudio/datasets
byte-compiling build/bdist.linux-x86_64/egg/torchaudio/transforms.py to transforms.pyc
byte-compiling build/bdist.linux-x86_64/egg/torchaudio/init.py to init.pyc
byte-compiling build/bdist.linux-x86_64/egg/torchaudio/datasets/init.py to init.pyc
byte-compiling build/bdist.linux-x86_64/egg/torchaudio/datasets/yesno.py to yesno.pyc
byte-compiling build/bdist.linux-x86_64/egg/torchaudio/datasets/vctk.py to vctk.pyc
creating stub loader for _torch_sox.so
byte-compiling build/bdist.linux-x86_64/egg/_torch_sox.py to _torch_sox.pyc
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying torchaudio.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying torchaudio.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying torchaudio.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
zip_safe flag not set; analyzing archive contents...
copying torchaudio.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
writing build/bdist.linux-x86_64/egg/EGG-INFO/native_libs.txt
creating dist
creating 'dist/torchaudio-0.1-py2.7-linux-x86_64.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing torchaudio-0.1-py2.7-linux-x86_64.egg
Copying torchaudio-0.1-py2.7-linux-x86_64.egg to /usr/local/lib/python2.7/dist-packages
Adding torchaudio 0.1 to easy-install.pth file

Installed /usr/local/lib/python2.7/dist-packages/torchaudio-0.1-py2.7-linux-x86_64.egg
Processing dependencies for torchaudio==0.1
Finished processing dependencies for torchaudio==0.1
Removing intermediate container ffaec8803f4a

Unable to install on OSX - fatal error: 'atomic' file not found #include <atomic>

$ python setup.py install

running install
running bdist_egg
running egg_info
writing torchaudio.egg-info/PKG-INFO
writing dependency_links to torchaudio.egg-info/dependency_links.txt
writing top-level names to torchaudio.egg-info/top_level.txt
reading manifest file 'torchaudio.egg-info/SOURCES.txt'
writing manifest file 'torchaudio.egg-info/SOURCES.txt'
installing library code to build/bdist.macosx-10.7-x86_64/egg
running install_lib
running build_py
running build_ext
building '_torch_sox' extension
gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/anaconda3/include -arch x86_64 -I/anaconda3/include -arch x86_64 -I/anaconda3/lib/python3.6/site-packages/torch/lib/include -I/anaconda3/lib/python3.6/site-packages/torch/lib/include/TH -I/anaconda3/lib/python3.6/site-packages/torch/lib/include/THC -I/anaconda3/include/python3.6m -c torchaudio/torch_sox.cpp -o build/temp.macosx-10.7-x86_64-3.6/torchaudio/torch_sox.o -DTORCH_EXTENSION_NAME=_torch_sox -std=c++11
In file included from torchaudio/torch_sox.cpp:1:
In file included from /anaconda3/lib/python3.6/site-packages/torch/lib/include/torch/torch.h:5:
In file included from /anaconda3/lib/python3.6/site-packages/torch/lib/include/ATen/ATen.h:5:
In file included from /anaconda3/lib/python3.6/site-packages/torch/lib/include/ATen/Allocator.h:6:
/anaconda3/lib/python3.6/site-packages/torch/lib/include/ATen/Retainable.h:3:10: fatal error: 'atomic' file not found
#include <atomic>
         ^~~~~~~~
1 error generated.
error: command 'gcc' failed with exit status 1

This is after installing sox and cloning the repo. Is there something I am missing?
I also tried upgrading my g++ to g++-8, but with no luck.

Any help appreciated!

libGOMP not found

I had an error similar to that reported here on trying to load torchaudio: pytorch/pytorch#643

I found that there were two independent things that would each lead to the error. One was compiling with an older version of gcc (4.8.something instead of 5.4.0). The other was importing torch before torchaudio.

undefined symbol when importing torchaudio with pytorch

Hi,
When importing torchaudio with pytorch 0.4.1 I get an undefined symbol. It does however work with v0.4.0. audio version: 7314b36

Successfully installed numpy-1.15.0 torch-cpu-0.4.1 torchaudio-0.1
(test_venv) [~]$ python -c "import torchaudio;"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "test_venv/lib/python3.6/site-packages/torchaudio/__init__.py", line 4, in <module>
    import _torch_sox
ImportError: test_venv/lib/python3.6/site-packages/_torch_sox.cpython-36m-x86_64-linux-gnu.so: undefined symbol: _ZN2at5ErrorC1ENS_14SourceLocationESs

Thanks

DownmixMono channels_first wrong default value

While the docs state the default value for channels_dim is True, it seems to be set to None instead as shown here.

This would yield to the default channel dimension as dim1:

channels_first = None
ch_dim = int(not channels_first)
print(ch_dim)
> 1

Reported in the forum here.

If you want, I could create a fast fix using channels_first=True as the default value or update the docs instead.

Best,
ptrblck

Build failed

I ran this command

python setup.py install &> log

and saw this error log

running install
running bdist_egg
running egg_info
writing torchaudio.egg-info/PKG-INFO
writing dependency_links to torchaudio.egg-info/dependency_links.txt
writing top-level names to torchaudio.egg-info/top_level.txt
reading manifest file 'torchaudio.egg-info/SOURCES.txt'
writing manifest file 'torchaudio.egg-info/SOURCES.txt'
installing library code to build/bdist.macosx-10.7-x86_64/egg
running install_lib
running build_py
running build_ext
building '_torch_sox' extension
gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/npkk/.pyenv/versions/anaconda3-5.1.0/envs/pytorch0.4.0/include -arch x86_64 -I/Users/npkk/.pyenv/versions/anaconda3-5.1.0/envs/pytorch0.4.0/include -arch x86_64 -I/Users/npkk/.pyenv/versions/anaconda3-5.1.0/envs/pytorch0.4.0/lib/python3.6/site-packages/torch/lib/include -I/Users/npkk/.pyenv/versions/anaconda3-5.1.0/envs/pytorch0.4.0/lib/python3.6/site-packages/torch/lib/include/TH -I/Users/npkk/.pyenv/versions/anaconda3-5.1.0/envs/pytorch0.4.0/lib/python3.6/site-packages/torch/lib/include/THC -I/Users/npkk/.pyenv/versions/anaconda3-5.1.0/envs/pytorch0.4.0/include/python3.6m -c torchaudio/torch_sox.cpp -o build/temp.macosx-10.7-x86_64-3.6/torchaudio/torch_sox.o -DTORCH_EXTENSION_NAME=_torch_sox -std=c++11
In file included from torchaudio/torch_sox.cpp:1:
In file included from /Users/npkk/.pyenv/versions/anaconda3-5.1.0/envs/pytorch0.4.0/lib/python3.6/site-packages/torch/lib/include/torch/torch.h:5:
In file included from /Users/npkk/.pyenv/versions/anaconda3-5.1.0/envs/pytorch0.4.0/lib/python3.6/site-packages/torch/lib/include/ATen/ATen.h:5:
In file included from /Users/npkk/.pyenv/versions/anaconda3-5.1.0/envs/pytorch0.4.0/lib/python3.6/site-packages/torch/lib/include/ATen/Allocator.h:6:
/Users/npkk/.pyenv/versions/anaconda3-5.1.0/envs/pytorch0.4.0/lib/python3.6/site-packages/torch/lib/include/ATen/Retainable.h:3:10: fatal error: 'atomic' file not found
#include <atomic>
         ^~~~~~~~
1 error generated.
/Users/npkk/.pyenv/versions/anaconda3-5.1.0/envs/pytorch0.4.0/lib/python3.6/site-packages/torch/utils/cpp_extension.py:106: UserWarning: 

                               !! WARNING !!

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Your compiler (g++) may be ABI-incompatible with PyTorch!
Please use a compiler that is ABI-compatible with GCC 4.9 and above.
See https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html.

See https://gist.github.com/goldsborough/d466f43e8ffc948ff92de7486c5216d6
for instructions on how to install GCC 4.9 or higher.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

                              !! WARNING !!

  warnings.warn(ABI_INCOMPATIBILITY_WARNING.format(compiler))
error: command 'gcc' failed with exit status 1

I thought that the build command

gcc -Wno-unused-result ... -std=c++11 

should be following...

g++ -Wno-unused-result ... -std=c++11

Python 3: Last Commit BREAKS usage of DeepSpeech.PyTorch with PyTorch Audio

The last commit BREAKS using PyTorch Audio with Python 3.

f80d6e3

Traceback (most recent call last):
  File "train.py", line 381, in <module>
    main()
  File "train.py", line 210, in main
    for i, (data) in enumerate(train_loader, start=start_iter):
  File "/home/dlm/anaconda3/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 212, in __next__
    return self._process_next_batch(batch)
  File "/home/dlm/anaconda3/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 239, in _process_next_batch
    raise batch.exc_type(batch.exc_msg)
TypeError: Traceback (most recent call last):
  File "/home/dlm/anaconda3/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 41, in _worker_loop
    samples = collate_fn([dataset[i] for i in batch_indices])
  File "/home/dlm/anaconda3/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 41, in <listcomp>
    samples = collate_fn([dataset[i] for i in batch_indices])
  File "/home/dlm/code/deepspeech.pytorch/data/data_loader.py", line 159, in __getitem__
    spect = self.parse_audio(audio_path)
  File "/home/dlm/code/deepspeech.pytorch/data/data_loader.py", line 106, in parse_audio
    y = load_audio(audio_path)
  File "/home/dlm/code/deepspeech.pytorch/data/data_loader.py", line 17, in load_audio
    sound, _ = torchaudio.load(path.encode('utf-8'))  # py3 fix
  File "/home/dlm/anaconda3/lib/python3.6/site-packages/torchaudio-0.1-py3.6-linux-x86_64.egg/torchaudio/__init__.py", line 26, in load
    func(bytes(filename, "ascii"), out, sample_rate_p)
TypeError: encoding without a string argument

Saving stereo files causes fatal error if re-loading generated file

Saving stereo files does not properly add the length info to the saved file. Thus you cannot reload these files with torchaudio, although they are playable in most audio programs. Below is a test case.

import torchaudio
sig, sr = torchaudio.load("test/steam-train-whistle-daniel_simon.mp3")
torchaudio.save("test/file.wav", sig, sr)
sig, sr = torchaudio.load("test/file.wav")

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/dhpollack/repos/audio/torchaudio/__init__.py", line 30, in load
    func(str(filepath).encode("utf-8"), out, sample_rate_p)
  File "/home/dhpollack/miniconda3/lib/python3.6/site-packages/torch/utils/ffi/__init__.py", line 177, in safe_cal
l
    result = torch._C._safe_call(*args, **kwargs)
torch.FatalError: [read_audio] Unknown length at torchaudio/src/generic/th_sox.c:14

cannot download libsox-dev and libsox-fmt-all

I work in a network of linux clusters and cant use sudo command: sudo apt-get install sox libsox-dev libsox-fmt-all
howelse can I install libsox-dev and libsox-fmt-all ?
I tried all ways but getting stuck with some error occuring while building '_torch_sox' extension.
Any help would be appreciated.

Unable to install

Hi,

I am unable to install torchaudio. Getting the following error when I try to install. The dependencies mentioned in the installation instructions have been installed. Any idea why this might be happening?

python setup.py install
running install
running bdist_egg
running egg_info
writing torchaudio.egg-info/PKG-INFO
writing dependency_links to torchaudio.egg-info/dependency_links.txt
writing requirements to torchaudio.egg-info/requires.txt
writing top-level names to torchaudio.egg-info/top_level.txt
reading manifest file 'torchaudio.egg-info/SOURCES.txt'
writing manifest file 'torchaudio.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
copying torchaudio/_ext/th_sox/init.py -> build/lib.linux-x86_64-3.6/torchaudio/_ext/th_sox
running build_ext
generating cffi module 'build/temp.linux-x86_64-3.6/torchaudio._ext.th_sox._th_sox.c'
already up-to-date
building 'torchaudio._ext.th_sox._th_sox' extension
x86_64-conda_cos6-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -fwrapv -O2 -Wall -Wstrict-prototypes -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -pipe -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -pipe -fPIC -I/home/paperspace/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include -I/home/paperspace/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH -Itorchaudio/src -I/home/paperspace/anaconda3/include/python3.6m -c build/temp.linux-x86_64-3.6/torchaudio._ext.th_sox._th_sox.c -o build/temp.linux-x86_64-3.6/build/temp.linux-x86_64-3.6/torchaudio._ext.th_sox._th_sox.o
unable to execute 'x86_64-conda_cos6-linux-gnu-gcc': No such file or directory
error: command 'x86_64-conda_cos6-linux-gnu-gcc' failed with exit status 1

Envnet model and related transforms

Hey,

I'm implementing EnvNet with ESC50 dataset with pytorch, it works great, but I would like to pull it into torchaudio.
So far I'm using the utils from bc_learning , what would be the best way to put this utils in torch audio ? should I rewrite the utils to be full pytorch or leave it in numpy (as in torchvision, the PIL Image in transforms.py)

ImportError when using pytorch compiled from the master branch with CUDA 10

I have compiled pytorch from the master branch using Python 3.7.1 and CUDA 10. Everything except pytorch-audio works. I receive this error when trying to import.

~/.pyenv/versions/3.7.1/envs/pytorch-venv/lib/python3.7/site-packages/torchaudio/__init__.py in <module>
      2 
      3 import torch
----> 4 import _torch_sox
      5 
      6 from torchaudio import transforms

ImportError: /home/kureta/.pyenv/versions/3.7.1/envs/pytorch-venv/lib/python3.7/site-packages/_torch_sox.cpython-37m-x86_64-linux-gnu.so: undefined symbol: _ZN2at18SparseCUDATensorIdEv

I can provide additional information if necessary.

Making Spectrogram as a layer

Having the spectrogram transform be a layer for a custom model has big benefits (GPU computation, no need to store the transforms, etc.). Similar to kapre (more in this paper). Making a few modifications to the SPECTROGRAM class would allow for such usage (subclassing nn.Module, using nn.Paramater instead of autograd.Variable for the window, etc.). Thoughts?

Error while importing torchaudio

Hi
I am getting this error while importing torchaudio. can someone please help me solve this.
Python 2.7.14 |Anaconda custom (64-bit)| (default, Oct 16 2017, 17:29:19)
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import torchaudio
Traceback (most recent call last):
File "", line 1, in
File "build/bdist.linux-x86_64/egg/torchaudio/init.py", line 11, in
from torchaudio import transforms
File "build/bdist.linux-x86_64/egg/torchaudio/transforms.py", line 152, in
class SPECTROGRAM(object):
File "build/bdist.linux-x86_64/egg/torchaudio/transforms.py", line 166, in SPECTROGRAM
pad=0, window=torch.hann_window, wkwargs=None):
AttributeError: 'module' object has no attribute 'hann_window'

Windows support

Now that PyTorch 0.4.0 supports Windows does torchaudio support Windows ? If yes could the installation instructions for the dependencies for Windows be added to the README. Thanks

On test example -- TypeError: initializer for ctype 'char *' must be a bytes or list or tuple, not str

For the test script:

import torchaudio
y, sr = torchaudio.load("test/wave_000000_lib.wav")
print(y, sr)
torchaudio.save("test/wave_000000_torch.wav", y, sr)

I get the output:

-1.5139e+07
-1.6122e+07
-1.7498e+07
     ⋮      
 1.7695e+06
 1.7039e+06
 9.8304e+05
[torch.FloatTensor of size 38400x1]
 22000
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-7-74b7b84c18a8> in <module>()
      2 y, sr = torchaudio.load("test/wave_000000_lib.wav")
      3 print(y, sr)
----> 4 torchaudio.save("test/wave_000000_torch.wav", y, sr)

/usr/local/miniconda3/lib/python3.6/site-packages/torchaudio-0.1-py3.6-macosx-10.7-x86_64.egg/torchaudio/__init__.py in save(filepath, src, sample_rate)
     38     func = getattr(th_sox, 'libthsox_{}_write_audio_file'.format(typename))
     39 
---> 40     func(bytes(filepath, "ascii"), src, extension[1:], sample_rate)

/usr/local/miniconda3/lib/python3.6/site-packages/torch/utils/ffi/__init__.py in safe_call(*args, **kwargs)
    175                      for arg in args)
    176         args = (function,) + args
--> 177         result = torch._C._safe_call(*args, **kwargs)
    178         if isinstance(result, ffi.CData):
    179             typeof = ffi.typeof(result)

TypeError: initializer for ctype 'char *' must be a bytes or list or tuple, not str

Any idea what's going on?

For reference, the .wav file is saved in float32 format; it seems like sox is configured to read it in int16 format, hence the large numbers. But I feel like that's not the problem, but rather the string used in the save method.

MacOS X 10.13 Installation Issue

Obtaining file:///Users/grokmachine/pytorch/audio
Installing collected packages: torchaudio
  Running setup.py develop for torchaudio
    Complete output from command /Users/grokmachine/anaconda3/envs/torch/bin/python -c "import setuptools, tokenize;__file__='/Users/grokmachine/pytorch/audio/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" develop --no-deps:
    which: no nvcc in (/Users/grokmachine/anaconda3/envs/torch/bin:/Users/grokmachine/anaconda3/bin:/Users/grokmachine/.cargo/bin:/usr/local/opt/mysql-client/bin:/usr/local/opt/gettext/bin:/usr/local/opt/icu4c/sbin:/usr/local/opt/icu4c/bin:/usr/local/opt/berkeley-db@4/bin:/usr/local/opt/llvm/bin:/usr/local/opt/llvm/bin:/usr/local/sbin:/Users/grokmachine/bin:/usr/local/bin:/usr/local/opt/mysql-client/bin:/usr/local/opt/gettext/bin:/usr/local/opt/icu4c/sbin:/usr/local/opt/icu4c/bin:/usr/local/opt/berkeley-db@4/bin:/usr/local/opt/llvm/bin:/usr/local/opt/llvm/bin:/usr/local/sbin:/Users/grokmachine/bin:/usr/local/bin:/Users/grokmachine/.cargo/bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/usr/local/MacGPG2/bin:/Applications/Wireshark.app/Contents/MacOS)
    running develop
    running egg_info
    writing torchaudio.egg-info/PKG-INFO
    writing dependency_links to torchaudio.egg-info/dependency_links.txt
    writing top-level names to torchaudio.egg-info/top_level.txt
    reading manifest file 'torchaudio.egg-info/SOURCES.txt'
    writing manifest file 'torchaudio.egg-info/SOURCES.txt'
    running build_ext
    building '_torch_sox' extension
    gcc -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/lib/python3.7/site-packages/numpy/core/include/ -I/Users/grokmachine/pytorch/pytorch/torch/lib/include -I/Users/grokmachine/pytorch/pytorch/torch/lib/include/TH -I/Users/grokmachine/pytorch/pytorch/torch/lib/include/THC -I/Users/grokmachine/anaconda3/envs/torch/include/python3.7m -c torchaudio/torch_sox.cpp -o build/temp.macosx-10.7-x86_64-3.7/torchaudio/torch_sox.o -DTORCH_EXTENSION_NAME=_torch_sox -std=c++11
    In file included from torchaudio/torch_sox.cpp:1:
    In file included from /Users/grokmachine/pytorch/pytorch/torch/lib/include/torch/torch.h:5:
    In file included from /Users/grokmachine/pytorch/pytorch/torch/lib/include/pybind11/pybind11.h:43:
    In file included from /Users/grokmachine/pytorch/pytorch/torch/lib/include/pybind11/attr.h:13:
    In file included from /Users/grokmachine/pytorch/pytorch/torch/lib/include/pybind11/cast.h:13:
    In file included from /Users/grokmachine/pytorch/pytorch/torch/lib/include/pybind11/pytypes.h:12:
    /Users/grokmachine/pytorch/pytorch/torch/lib/include/pybind11/detail/common.h:139:10: fatal error: 'forward_list' file not found
    #include <forward_list>
             ^~~~~~~~~~~~~~
    1 error generated.
    error: command 'gcc' failed with exit status 1

    ----------------------------------------
Command "/Users/grokmachine/anaconda3/envs/torch/bin/python -c "import setuptools, tokenize;__file__='/Users/grokmachine/pytorch/audio/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" develop --no-deps" failed with error code 1 in /Users/grokmachine/pytorch/audio/

So I tried using clang instead, still the same error

 grokmachine@spock   ~/pytorch/audio     master  CC=clang CXX=clang++ pip install -e .
Obtaining file:///Users/grokmachine/pytorch/audio
Installing collected packages: torchaudio
  Running setup.py develop for torchaudio
    Complete output from command /Users/grokmachine/anaconda3/envs/torch/bin/python -c "import setuptools, tokenize;__file__='/Users/grokmachine/pytorch/audio/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" develop --no-deps:
    which: no nvcc in (/Users/grokmachine/anaconda3/envs/torch/bin:/Users/grokmachine/anaconda3/bin:/Users/grokmachine/.cargo/bin:/usr/local/opt/mysql-client/bin:/usr/local/opt/gettext/bin:/usr/local/opt/icu4c/sbin:/usr/local/opt/icu4c/bin:/usr/local/opt/berkeley-db@4/bin:/usr/local/opt/llvm/bin:/usr/local/opt/llvm/bin:/usr/local/sbin:/Users/grokmachine/bin:/usr/local/bin:/usr/local/opt/mysql-client/bin:/usr/local/opt/gettext/bin:/usr/local/opt/icu4c/sbin:/usr/local/opt/icu4c/bin:/usr/local/opt/berkeley-db@4/bin:/usr/local/opt/llvm/bin:/usr/local/opt/llvm/bin:/usr/local/sbin:/Users/grokmachine/bin:/usr/local/bin:/Users/grokmachine/.cargo/bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/usr/local/MacGPG2/bin:/Applications/Wireshark.app/Contents/MacOS)
    running develop
    running egg_info
    writing torchaudio.egg-info/PKG-INFO
    writing dependency_links to torchaudio.egg-info/dependency_links.txt
    writing top-level names to torchaudio.egg-info/top_level.txt
    reading manifest file 'torchaudio.egg-info/SOURCES.txt'
    writing manifest file 'torchaudio.egg-info/SOURCES.txt'
    running build_ext
    building '_torch_sox' extension
    clang -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/lib/python3.7/site-packages/numpy/core/include/ -I/Users/grokmachine/pytorch/pytorch/torch/lib/include -I/Users/grokmachine/pytorch/pytorch/torch/lib/include/TH -I/Users/grokmachine/pytorch/pytorch/torch/lib/include/THC -I/Users/grokmachine/anaconda3/envs/torch/include/python3.7m -c torchaudio/torch_sox.cpp -o build/temp.macosx-10.7-x86_64-3.7/torchaudio/torch_sox.o -DTORCH_EXTENSION_NAME=_torch_sox -std=c++11
    In file included from torchaudio/torch_sox.cpp:1:
    In file included from /Users/grokmachine/pytorch/pytorch/torch/lib/include/torch/torch.h:5:
    In file included from /Users/grokmachine/pytorch/pytorch/torch/lib/include/pybind11/pybind11.h:43:
    In file included from /Users/grokmachine/pytorch/pytorch/torch/lib/include/pybind11/attr.h:13:
    In file included from /Users/grokmachine/pytorch/pytorch/torch/lib/include/pybind11/cast.h:13:
    In file included from /Users/grokmachine/pytorch/pytorch/torch/lib/include/pybind11/pytypes.h:12:
    /Users/grokmachine/pytorch/pytorch/torch/lib/include/pybind11/detail/common.h:139:10: fatal error: 'forward_list' file not found
    #include <forward_list>
             ^~~~~~~~~~~~~~
    1 error generated.
    error: command 'clang' failed with exit status 1

    ----------------------------------------
Command "/Users/grokmachine/anaconda3/envs/torch/bin/python -c "import setuptools, tokenize;__file__='/Users/grokmachine/pytorch/audio/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" develop --no-deps" failed with error code 1 in /Users/grokmachine/pytorch/audio/

but if I use the latest gcc-8

 grokmachine@spock   ~/pytorch/audio     master  CC=gcc-8 CXX=g++-8 pip install -e .   1 ↵  10209  17:42:41
Obtaining file:///Users/grokmachine/pytorch/audio
Installing collected packages: torchaudio
  Running setup.py develop for torchaudio
Successfully installed torchaudio```

No handler for .mp4 format.

When I try to read an audio track from .mp4 file (Kinetics dataset),
I get the following error:
formats: no handler for file extension 'mp4'
with the full stack trace:

~/bin/miniconda3/envs/pytorch03/lib/python3.6/site-packages/torch/utils/ffi/__init__.py in safe_call(*args, **kwargs)
    178                      for arg in args)
    179         args = (function,) + args
--> 180         result = torch._C._safe_call(*args, **kwargs)
    181         if isinstance(result, ffi.CData):
    182             typeof = ffi.typeof(result)

FatalError: [read_audio_file] Failure to read file at torchaudio/src/generic/th_sox.c:42

I take it it has something to do with my SoX install, but for the life of me can't figure out what I'm missing. Any ideas?

different library for loading audio files

I read that PyTorch doesn't want to add complex number tensor types. A lot of audio processing requires fourier transforms, specifically into MEL spectrograms. It would be nice to use a library that already handles a lot of these transformations in numpy. The most popular one seems to be librosa, which uses numpy arrays for easy conversion to torch tensors.

Is there any reason this library uses a cffi extension instead of a library such as librosa?

There are actually a lot more reasons to use librosa rather than the current solution, but it'd take too long to list them. I wouldn't mind making a pull request to switch from the current libsox cffi way of doing things to the librosa/numpy way.

Segmentation fault (core dumped)

I'm unable to load any file after first time installation. I faced an issue #53 which I somehow resolved by modifying setup.py file, but am not sure if it is the correct way...
OS: " CentOS Linux release 7.2.1511 (Core)"

[1]: import torchaudio
[2]: torchaudio.load('speech-data/can-you-get-it.wav')
Segmentation fault (core dumped)

weird case w/ torchaudio / yaafe / jupyter crashes kernel, not sure where to start

Hi!

I am getting a super weird bug and I have no idea where to start (so I'm here).

As of right now, this is only happening in the following scenario:

Inside a jupyter notebook,

import torchaudio
import yaafelib
yaafelib.FeaturePlan(sample_rate=22000)

I get an invalid pointer. Partial trace at bottom.

If i reverse the import orders

import yaafelib
import torchaudio
yaafelib.FeaturePlan(sample_rate=22000)

It doesn't happen.

If I don't run in a jupyter notebook, it doesn't happen.

partial stack trace (can put rest.. just long).

*** Error in `/home/brian/anaconda3/envs/py3torch/bin/python': free(): invalid pointer: 0x00007f99ace84ae0 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7f99d3cd67e5]
/lib/x86_64-linux-gnu/libc.so.6(+0x8037a)[0x7f99d3cdf37a]
/lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7f99d3ce353c]
/home/brian/anaconda3/envs/py3torch/lib/python3.6/site-packages/zmq/backend/cython/../../../../.././libstdc++.so.6(_ZNSt15basic_stringbufIcSt11char_traitsIcESaIcEE8overflowEi+0x160)[0x7f99cd4a77e0]
/home/brian/anaconda3/envs/py3torch/lib/python3.6/site-packages/zmq/backend/cython/../../../../.././libstdc++.so.6(_ZNSt15basic_streambufIcSt11char_traitsIcEE6xsputnEPKcl+0x89)[0x7f99cd4fa759]
/home/brian/anaconda3/envs/py3torch/lib/python3.6/site-packages/torch/lib/libshm.so(_ZNKSt7num_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE15_M_insert_floatIdEES3_S3_RSt8ios_baseccT_+0x26c)[0x7f99acc234fc]
/home/brian/anaconda3/envs/py3torch/lib/python3.6/site-packages/torch/lib/libshm.so(_ZNKSt7num_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE6do_putES3_RSt8ios_basecd+0x10)[0x7f99acc23600]
/home/brian/anaconda3/envs/py3torch/lib/python3.6/site-packages/torch/lib/libshm.so(_ZNSo9_M_insertIdEERSoT_+0xb5)[0x7f99acbfa125]
/home/brian/anaconda3/envs/py3torch/lib/python3.6/lib-dynload/../.././libyaafe-core.so.0(_ZN5YAAFE16ComponentFactory7versionEv+0x189)[0x7f997e6050c9]
/home/brian/anaconda3/envs/py3torch/lib/python3.6/lib-dynload/_ctypes.cpython-36m-x86_64-linux-gnu.so(ffi_call_unix64+0x4c)[0x7f99cdc2b550]
/home/brian/anaconda3/envs/py3torch/lib/python3.6/lib-dynload/_ctypes.cpython-36m-x86_64-linux-gnu.so(ffi_call+0x1f5)[0x7f99cdc2acf5]
/home/brian/anaconda3/envs/py3torch/lib/python3.6/lib-dynload/_ctypes.cpython-36m-x86_64-linux-gnu.so(_ctypes_callproc+0x3dc)[0x7f99cdc2283c]
/home/brian/anaconda3/envs/py3torch/lib/python3.6/lib-dynload/_ctypes.cpython-36m-x86_64-linux-gnu.so(+0x9da3)[0x7f99cdc1ada3]
/home/brian/anaconda3/envs/py3torch/bin/../lib/libpython3.6m.so.1.0(_PyObject_FastCallDict+0x9e)[0x7f99d4bc9ade]
/home/brian/anaconda3/envs/py3torch/bin/../lib/libpython3.6m.so.1.0(+0x1482bb)[0x7f99d4ca62bb]
/home/brian/anaconda3/envs/py3torch/bin/../lib/libpython3.6m.so.1.0(_PyEval_EvalFrameDefault+0x26fd)[0x7f99d4ca915d]
/home/brian/anaconda3/envs/py3torch/bin/../lib/libpython3.6m.so.1.0(+0x145e74)[0x7f99d4ca3e74]
/home/brian/anaconda3/envs/py3torch/bin/../lib/libpython3.6m.so.1.0(+0x1485e8)[0x7f99d4ca65e8]
/home/brian/anaconda3/envs/py3torch/bin/../lib/libpython3.6m.so.1.0(_PyEval_EvalFrameDefault+0x26fd)[0x7f99d4ca915d]
/home/brian/anaconda3/envs/py3torch/bin/../lib/libpython3.6m.so.1.0(+0x146a60)[0x7f99d4ca4a60]
/home/brian/anaconda3/envs/py3torch/bin/../lib/libpython3.6m.so.1.0(_PyFunction_FastCallDict+0x10c)[0x7f99d4ca4cfc]
/home/brian/anaconda3/envs/py3torch/bin/../lib/libpython3.6m.so.1.0(_PyObject_FastCallDict+0x166)[0x7f99d4bc9ba6]
/home/brian/anaconda3/envs/py3torch/bin/../lib/libpython3.6m.so.1.0(_PyObject_Call_Prepend+0xcc)[0x7f99d4bc9dfc]
/home/brian/anaconda3/envs/py3torch/bin/../lib/libpython3.6m.so.1.0(PyObject_Call+0x56)[0x7f99d4bc9e96]

ModuleNotFoundError: No module named 'torchaudio._ext.th_sox._th_sox'

Hi. Even though I've got sox installed, I get a 'module not found' error.
This is on Mac, with Anaconda & Python 3.6...

$ python
Python 3.6.5 | packaged by conda-forge | (default, Apr  6 2018, 13:44:09) 
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import torchaudio
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/shawley/Downloads/audio/torchaudio/__init__.py", line 9, in <module>
    from ._ext import th_sox
  File "/Users/shawley/Downloads/audio/torchaudio/_ext/th_sox/__init__.py", line 3, in <module>
    from ._th_sox import lib as _lib, ffi as _ffi
ModuleNotFoundError: No module named 'torchaudio._ext.th_sox._th_sox'
>>> 

This is after following installation instructions.
Any suggestions? Thanks.

Install log follows below...

$ git clone https://github.com/pytorch/audio.git
Cloning into 'audio'...
remote: Counting objects: 304, done.
remote: Compressing objects: 100% (45/45), done.
remote: Total 304 (delta 24), reused 19 (delta 10), pack-reused 249
Receiving objects: 100% (304/304), 4.85 MiB | 1.24 MiB/s, done.
Resolving deltas: 100% (106/106), done.

$ brew install sox
Error: sox 14.4.2 is already installed
To upgrade to 14.4.2_1, run `brew upgrade sox`

$ brew upgrade sox
==> Upgrading 1 outdated package, with result:
sox 14.4.2 -> 14.4.2_1
==> Upgrading sox 
==> Downloading https://homebrew.bintray.com/bottles/sox-14.4.2_1.high_sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring sox-14.4.2_1.high_sierra.bottle.tar.gz
🍺  /usr/local/Cellar/sox/14.4.2_1: 23 files, 1.8MB

$ pip install cffi
Requirement already satisfied: cffi in /Users/shawley/anaconda/envs/py36/lib/python3.6/site-packages (1.11.5)
Requirement already satisfied: pycparser in /Users/shawley/anaconda/envs/py36/lib/python3.6/site-packages (from cffi) (2.18)


$ $ python setup.py install
running install
running bdist_egg
running egg_info
creating torchaudio.egg-info
writing torchaudio.egg-info/PKG-INFO
writing dependency_links to torchaudio.egg-info/dependency_links.txt
writing requirements to torchaudio.egg-info/requires.txt
writing top-level names to torchaudio.egg-info/top_level.txt
writing manifest file 'torchaudio.egg-info/SOURCES.txt'
reading manifest file 'torchaudio.egg-info/SOURCES.txt'
writing manifest file 'torchaudio.egg-info/SOURCES.txt'
installing library code to build/bdist.macosx-10.9-x86_64/egg
running install_lib
running build_py
creating build
creating build/lib.macosx-10.9-x86_64-3.6
creating build/lib.macosx-10.9-x86_64-3.6/torchaudio
copying torchaudio/transforms.py -> build/lib.macosx-10.9-x86_64-3.6/torchaudio
copying torchaudio/__init__.py -> build/lib.macosx-10.9-x86_64-3.6/torchaudio
creating build/lib.macosx-10.9-x86_64-3.6/torchaudio/datasets
copying torchaudio/datasets/__init__.py -> build/lib.macosx-10.9-x86_64-3.6/torchaudio/datasets
copying torchaudio/datasets/yesno.py -> build/lib.macosx-10.9-x86_64-3.6/torchaudio/datasets
copying torchaudio/datasets/vctk.py -> build/lib.macosx-10.9-x86_64-3.6/torchaudio/datasets
creating build/lib.macosx-10.9-x86_64-3.6/torchaudio/_ext
copying torchaudio/_ext/__init__.py -> build/lib.macosx-10.9-x86_64-3.6/torchaudio/_ext
creating build/lib.macosx-10.9-x86_64-3.6/torchaudio/_ext/th_sox
copying torchaudio/_ext/th_sox/__init__.py -> build/lib.macosx-10.9-x86_64-3.6/torchaudio/_ext/th_sox
running build_ext
generating cffi module 'build/temp.macosx-10.9-x86_64-3.6/torchaudio._ext.th_sox._th_sox.c'
creating build/temp.macosx-10.9-x86_64-3.6
building 'torchaudio._ext.th_sox._th_sox' extension
creating build/temp.macosx-10.9-x86_64-3.6/build
creating build/temp.macosx-10.9-x86_64-3.6/build/temp.macosx-10.9-x86_64-3.6
creating build/temp.macosx-10.9-x86_64-3.6/Users
creating build/temp.macosx-10.9-x86_64-3.6/Users/shawley
creating build/temp.macosx-10.9-x86_64-3.6/Users/shawley/Downloads
creating build/temp.macosx-10.9-x86_64-3.6/Users/shawley/Downloads/audio
creating build/temp.macosx-10.9-x86_64-3.6/Users/shawley/Downloads/audio/torchaudio
creating build/temp.macosx-10.9-x86_64-3.6/Users/shawley/Downloads/audio/torchaudio/src
gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/shawley/anaconda/envs/py36/include -arch x86_64 -I/Users/shawley/anaconda/envs/py36/include -arch x86_64 -I/Users/shawley/anaconda/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include -I/Users/shawley/anaconda/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH -Itorchaudio/src -I/Users/shawley/anaconda/envs/py36/include/python3.6m -c build/temp.macosx-10.9-x86_64-3.6/torchaudio._ext.th_sox._th_sox.c -o build/temp.macosx-10.9-x86_64-3.6/build/temp.macosx-10.9-x86_64-3.6/torchaudio._ext.th_sox._th_sox.o
gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/shawley/anaconda/envs/py36/include -arch x86_64 -I/Users/shawley/anaconda/envs/py36/include -arch x86_64 -I/Users/shawley/anaconda/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include -I/Users/shawley/anaconda/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH -Itorchaudio/src -I/Users/shawley/anaconda/envs/py36/include/python3.6m -c /Users/shawley/Downloads/audio/torchaudio/src/th_sox.c -o build/temp.macosx-10.9-x86_64-3.6/Users/shawley/Downloads/audio/torchaudio/src/th_sox.o
In file included from /Users/shawley/Downloads/audio/torchaudio/src/th_sox.c:11:
In file included from /Users/shawley/anaconda/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH/THGenerateAllTypes.h:10:
In file included from /Users/shawley/anaconda/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH/THGenerateFloatTypes.h:10:
In file included from generic/th_sox.c:1:
torchaudio/src/generic/th_sox.c:11:18: warning: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Wsign-compare]
    if (nsamples != -1) {
        ~~~~~~~~ ^  ~~
torchaudio/src/generic/th_sox.c:27:14: warning: comparison of integers of different signs: 'int' and 'unsigned long' [-Wsign-compare]
  for (x=0; x<samples_read/nchannels; x++) {
            ~^~~~~~~~~~~~~~~~~~~~~~~
In file included from /Users/shawley/Downloads/audio/torchaudio/src/th_sox.c:11:
In file included from /Users/shawley/anaconda/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH/THGenerateAllTypes.h:10:
In file included from /Users/shawley/anaconda/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH/THGenerateFloatTypes.h:11:
In file included from generic/th_sox.c:1:
torchaudio/src/generic/th_sox.c:11:18: warning: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Wsign-compare]
    if (nsamples != -1) {
        ~~~~~~~~ ^  ~~
torchaudio/src/generic/th_sox.c:27:14: warning: comparison of integers of different signs: 'int' and 'unsigned long' [-Wsign-compare]
  for (x=0; x<samples_read/nchannels; x++) {
            ~^~~~~~~~~~~~~~~~~~~~~~~
In file included from /Users/shawley/Downloads/audio/torchaudio/src/th_sox.c:11:
In file included from /Users/shawley/anaconda/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH/THGenerateAllTypes.h:11:
In file included from /Users/shawley/anaconda/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH/THGenerateIntTypes.h:10:
In file included from generic/th_sox.c:1:
torchaudio/src/generic/th_sox.c:11:18: warning: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Wsign-compare]
    if (nsamples != -1) {
        ~~~~~~~~ ^  ~~
torchaudio/src/generic/th_sox.c:27:14: warning: comparison of integers of different signs: 'int' and 'unsigned long' [-Wsign-compare]
  for (x=0; x<samples_read/nchannels; x++) {
            ~^~~~~~~~~~~~~~~~~~~~~~~
In file included from /Users/shawley/Downloads/audio/torchaudio/src/th_sox.c:11:
In file included from /Users/shawley/anaconda/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH/THGenerateAllTypes.h:11:
In file included from /Users/shawley/anaconda/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH/THGenerateIntTypes.h:11:
In file included from generic/th_sox.c:1:
torchaudio/src/generic/th_sox.c:11:18: warning: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Wsign-compare]
    if (nsamples != -1) {
        ~~~~~~~~ ^  ~~
torchaudio/src/generic/th_sox.c:27:14: warning: comparison of integers of different signs: 'int' and 'unsigned long' [-Wsign-compare]
  for (x=0; x<samples_read/nchannels; x++) {
            ~^~~~~~~~~~~~~~~~~~~~~~~
In file included from /Users/shawley/Downloads/audio/torchaudio/src/th_sox.c:11:
In file included from /Users/shawley/anaconda/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH/THGenerateAllTypes.h:11:
In file included from /Users/shawley/anaconda/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH/THGenerateIntTypes.h:12:
In file included from generic/th_sox.c:1:
torchaudio/src/generic/th_sox.c:11:18: warning: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Wsign-compare]
    if (nsamples != -1) {
        ~~~~~~~~ ^  ~~
torchaudio/src/generic/th_sox.c:27:14: warning: comparison of integers of different signs: 'int' and 'unsigned long' [-Wsign-compare]
  for (x=0; x<samples_read/nchannels; x++) {
            ~^~~~~~~~~~~~~~~~~~~~~~~
In file included from /Users/shawley/Downloads/audio/torchaudio/src/th_sox.c:11:
In file included from /Users/shawley/anaconda/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH/THGenerateAllTypes.h:11:
In file included from /Users/shawley/anaconda/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH/THGenerateIntTypes.h:13:
In file included from generic/th_sox.c:1:
torchaudio/src/generic/th_sox.c:11:18: warning: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Wsign-compare]
    if (nsamples != -1) {
        ~~~~~~~~ ^  ~~
torchaudio/src/generic/th_sox.c:27:14: warning: comparison of integers of different signs: 'int' and 'unsigned long' [-Wsign-compare]
  for (x=0; x<samples_read/nchannels; x++) {
            ~^~~~~~~~~~~~~~~~~~~~~~~
In file included from /Users/shawley/Downloads/audio/torchaudio/src/th_sox.c:11:
In file included from /Users/shawley/anaconda/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH/THGenerateAllTypes.h:11:
In file included from /Users/shawley/anaconda/envs/py36/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH/THGenerateIntTypes.h:14:
In file included from generic/th_sox.c:1:
torchaudio/src/generic/th_sox.c:11:18: warning: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Wsign-compare]
    if (nsamples != -1) {
        ~~~~~~~~ ^  ~~
torchaudio/src/generic/th_sox.c:27:14: warning: comparison of integers of different signs: 'int' and 'unsigned long' [-Wsign-compare]
  for (x=0; x<samples_read/nchannels; x++) {
            ~^~~~~~~~~~~~~~~~~~~~~~~
14 warnings generated.
gcc -bundle -undefined dynamic_lookup -Wl,-rpath,/Users/shawley/anaconda/envs/py36/lib -L/Users/shawley/anaconda/envs/py36/lib -headerpad_max_install_names -Wl,-rpath,/Users/shawley/anaconda/envs/py36/lib -L/Users/shawley/anaconda/envs/py36/lib -headerpad_max_install_names -arch x86_64 build/temp.macosx-10.9-x86_64-3.6/build/temp.macosx-10.9-x86_64-3.6/torchaudio._ext.th_sox._th_sox.o build/temp.macosx-10.9-x86_64-3.6/Users/shawley/Downloads/audio/torchaudio/src/th_sox.o -L/Users/shawley/anaconda/envs/py36/lib -lsox -o build/lib.macosx-10.9-x86_64-3.6/torchaudio/_ext/th_sox/_th_sox.abi3.so
creating build/bdist.macosx-10.9-x86_64
creating build/bdist.macosx-10.9-x86_64/egg
creating build/bdist.macosx-10.9-x86_64/egg/torchaudio
copying build/lib.macosx-10.9-x86_64-3.6/torchaudio/transforms.py -> build/bdist.macosx-10.9-x86_64/egg/torchaudio
creating build/bdist.macosx-10.9-x86_64/egg/torchaudio/datasets
copying build/lib.macosx-10.9-x86_64-3.6/torchaudio/datasets/__init__.py -> build/bdist.macosx-10.9-x86_64/egg/torchaudio/datasets
copying build/lib.macosx-10.9-x86_64-3.6/torchaudio/datasets/yesno.py -> build/bdist.macosx-10.9-x86_64/egg/torchaudio/datasets
copying build/lib.macosx-10.9-x86_64-3.6/torchaudio/datasets/vctk.py -> build/bdist.macosx-10.9-x86_64/egg/torchaudio/datasets
copying build/lib.macosx-10.9-x86_64-3.6/torchaudio/__init__.py -> build/bdist.macosx-10.9-x86_64/egg/torchaudio
creating build/bdist.macosx-10.9-x86_64/egg/torchaudio/_ext
creating build/bdist.macosx-10.9-x86_64/egg/torchaudio/_ext/th_sox
copying build/lib.macosx-10.9-x86_64-3.6/torchaudio/_ext/th_sox/_th_sox.abi3.so -> build/bdist.macosx-10.9-x86_64/egg/torchaudio/_ext/th_sox
copying build/lib.macosx-10.9-x86_64-3.6/torchaudio/_ext/th_sox/__init__.py -> build/bdist.macosx-10.9-x86_64/egg/torchaudio/_ext/th_sox
copying build/lib.macosx-10.9-x86_64-3.6/torchaudio/_ext/__init__.py -> build/bdist.macosx-10.9-x86_64/egg/torchaudio/_ext
byte-compiling build/bdist.macosx-10.9-x86_64/egg/torchaudio/transforms.py to transforms.cpython-36.pyc
byte-compiling build/bdist.macosx-10.9-x86_64/egg/torchaudio/datasets/__init__.py to __init__.cpython-36.pyc
byte-compiling build/bdist.macosx-10.9-x86_64/egg/torchaudio/datasets/yesno.py to yesno.cpython-36.pyc
byte-compiling build/bdist.macosx-10.9-x86_64/egg/torchaudio/datasets/vctk.py to vctk.cpython-36.pyc
byte-compiling build/bdist.macosx-10.9-x86_64/egg/torchaudio/__init__.py to __init__.cpython-36.pyc
byte-compiling build/bdist.macosx-10.9-x86_64/egg/torchaudio/_ext/th_sox/__init__.py to __init__.cpython-36.pyc
byte-compiling build/bdist.macosx-10.9-x86_64/egg/torchaudio/_ext/__init__.py to __init__.cpython-36.pyc
creating stub loader for torchaudio/_ext/th_sox/_th_sox.abi3.so
byte-compiling build/bdist.macosx-10.9-x86_64/egg/torchaudio/_ext/th_sox/_th_sox.py to _th_sox.cpython-36.pyc
creating build/bdist.macosx-10.9-x86_64/egg/EGG-INFO
copying torchaudio.egg-info/PKG-INFO -> build/bdist.macosx-10.9-x86_64/egg/EGG-INFO
copying torchaudio.egg-info/SOURCES.txt -> build/bdist.macosx-10.9-x86_64/egg/EGG-INFO
copying torchaudio.egg-info/dependency_links.txt -> build/bdist.macosx-10.9-x86_64/egg/EGG-INFO
copying torchaudio.egg-info/requires.txt -> build/bdist.macosx-10.9-x86_64/egg/EGG-INFO
copying torchaudio.egg-info/top_level.txt -> build/bdist.macosx-10.9-x86_64/egg/EGG-INFO
writing build/bdist.macosx-10.9-x86_64/egg/EGG-INFO/native_libs.txt
zip_safe flag not set; analyzing archive contents...
torchaudio._ext.th_sox.__pycache__._th_sox.cpython-36: module references __file__
creating dist
creating 'dist/torchaudio-0.1-py3.6-macosx-10.9-x86_64.egg' and adding 'build/bdist.macosx-10.9-x86_64/egg' to it
removing 'build/bdist.macosx-10.9-x86_64/egg' (and everything under it)
Processing torchaudio-0.1-py3.6-macosx-10.9-x86_64.egg
creating /Users/shawley/anaconda/envs/py36/lib/python3.6/site-packages/torchaudio-0.1-py3.6-macosx-10.9-x86_64.egg
Extracting torchaudio-0.1-py3.6-macosx-10.9-x86_64.egg to /Users/shawley/anaconda/envs/py36/lib/python3.6/site-packages
Adding torchaudio 0.1 to easy-install.pth file

Installed /Users/shawley/anaconda/envs/py36/lib/python3.6/site-packages/torchaudio-0.1-py3.6-macosx-10.9-x86_64.egg
Processing dependencies for torchaudio==0.1
Searching for cffi==1.11.5
Best match: cffi 1.11.5
Adding cffi 1.11.5 to easy-install.pth file

Using /Users/shawley/anaconda/envs/py36/lib/python3.6/site-packages
Searching for pycparser==2.18
Best match: pycparser 2.18
Adding pycparser 2.18 to easy-install.pth file

Using /Users/shawley/anaconda/envs/py36/lib/python3.6/site-packages
Finished processing dependencies for torchaudio==0.1

Further poking around:

$ cat torchaudio/_ext/th_sox/__init__.py 

from torch.utils.ffi import _wrap_function
from ._th_sox import lib as _lib, ffi as _ffi

__all__ = []
def _import_symbols(locals):
    for symbol in dir(_lib):
        fn = getattr(_lib, symbol)
        if callable(fn):
            locals[symbol] = _wrap_function(fn, _ffi)
        else:
            locals[symbol] = fn
        __all__.append(symbol)

_import_symbols(locals())

...I don't see how this is supposed to import other modules from the th_sox directory if there's nothing else in there:

$ ls torchaudio/_ext/th_sox/
__init__.py      __pycache__/

??

Exception at 'import torchaudio'

Hi,
I am trying to use torchaudio on Ubuntu and get the following exception:

>>> import torchaudio
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "torchaudio/__init__.py", line 5, in <module>
    from ._ext import th_sox
  File "torchaudio/_ext/th_sox/__init__.py", line 3, in <module>
    from ._th_sox import lib as _lib, ffi as _ffi
ImportError: No module named _th_soxq

All dependencies are met and up-to-date:

libsox-dev is already the newest version.
libsox-fmt-all is already the newest version.
sox is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 196 not upgraded.

Also, install process seems ok, no errors or warnings:

running install
running bdist_egg
running egg_info
writing requirements to torchaudio.egg-info/requires.txt
writing torchaudio.egg-info/PKG-INFO
writing top-level names to torchaudio.egg-info/top_level.txt
writing dependency_links to torchaudio.egg-info/dependency_links.txt
reading manifest file 'torchaudio.egg-info/SOURCES.txt'
writing manifest file 'torchaudio.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
copying torchaudio/_ext/th_sox/__init__.py -> build/lib.linux-x86_64-2.7/torchaudio/_ext/th_sox
running build_ext
generating cffi module 'build/temp.linux-x86_64-2.7/torchaudio._ext._th_sox.c'
already up-to-date
creating build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/torchaudio
creating build/bdist.linux-x86_64/egg/torchaudio/_ext
creating build/bdist.linux-x86_64/egg/torchaudio/_ext/th_sox
copying build/lib.linux-x86_64-2.7/torchaudio/_ext/th_sox/__init__.py -> build/bdist.linux-x86_64/egg/torchaudio/_ext/th_sox
copying build/lib.linux-x86_64-2.7/torchaudio/_ext/_th_sox.so -> build/bdist.linux-x86_64/egg/torchaudio/_ext
copying build/lib.linux-x86_64-2.7/torchaudio/_ext/__init__.py -> build/bdist.linux-x86_64/egg/torchaudio/_ext
copying build/lib.linux-x86_64-2.7/torchaudio/__init__.py -> build/bdist.linux-x86_64/egg/torchaudio
byte-compiling build/bdist.linux-x86_64/egg/torchaudio/_ext/th_sox/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/torchaudio/_ext/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/torchaudio/__init__.py to __init__.pyc
creating stub loader for torchaudio/_ext/_th_sox.so
byte-compiling build/bdist.linux-x86_64/egg/torchaudio/_ext/_th_sox.py to _th_sox.pyc
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying torchaudio.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying torchaudio.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying torchaudio.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying torchaudio.egg-info/requires.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying torchaudio.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
writing build/bdist.linux-x86_64/egg/EGG-INFO/native_libs.txt
zip_safe flag not set; analyzing archive contents...
creating 'dist/torchaudio-0.1-py2.7-linux-x86_64.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing torchaudio-0.1-py2.7-linux-x86_64.egg
Removing /usr/local/lib/python2.7/dist-packages/torchaudio-0.1-py2.7-linux-x86_64.egg
Copying torchaudio-0.1-py2.7-linux-x86_64.egg to /usr/local/lib/python2.7/dist-packages
torchaudio 0.1 is already the active version in easy-install.pth

Installed /usr/local/lib/python2.7/dist-packages/torchaudio-0.1-py2.7-linux-x86_64.egg
Processing dependencies for torchaudio==0.1
Searching for cffi==1.10.0
Best match: cffi 1.10.0
Adding cffi 1.10.0 to easy-install.pth file

Using /usr/local/lib/python2.7/dist-packages
Searching for pycparser==2.17
Best match: pycparser 2.17
Adding pycparser 2.17 to easy-install.pth file

Using /usr/local/lib/python2.7/dist-packages
Finished processing dependencies for torchaudio==0.1

Any idea what went wrong?

Thanks!

tag for torch==0.3.X

I'm trying to install a repo that still uses torchaudio as a dependency and since the new pytorch 0.4 update, it's not possible to do a clean install from a new user point of view.

I guess I won't be the only one having this problem. Is it possible to make a tag on the last commit compatible with torch v0.3?

Thanks,
Miguel

Trying to load corrupt file segfaults instead of raising exception.

The problem

Trying to load an invalid file segfaults and crashes the entire process instead of raising an exception.

Steps to reproduce

$ touch test.mp3
$ python -c "import torchaudio; torchaudio.load('test.mp3')"
/home/kpar/.pyenv/versions/foley/lib/python3.7/site-packages/sklearn/externals/joblib/externals/cloudpickle/cloudpickle.py:47: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import imp
formats: can't open input file `test.mp3': Invalid argument
[1]    27224 segmentation fault (core dumped)  python -c "import torchaudio; torchaudio.load('test.mp3')"

GDB Backtrace

/home/kpar/.pyenv/versions/3.7.0/envs/foley/lib/python3.7/site-packages/sklearn/externals/joblib/externals/cloudpickle/cloudpickle.py:47: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import imp
formats: can't open input file `test.mp3': Invalid argument

Thread 1 "python" received signal SIGSEGV, Segmentation fault.
0x00007fffa92e0cb9 in sox_close () from /usr/lib/x86_64-linux-gnu/libsox.so.3
(gdb) bt
#0  0x00007fffa92e0cb9 in sox_close () from /usr/lib/x86_64-linux-gnu/libsox.so.3
#1  0x00007fffa955da1c in torch::audio::(anonymous namespace)::SoxDescriptor::~SoxDescriptor (this=0x7fffffffd368, __in_chrg=<optimized out>) at torchaudio/torch_sox.cpp:21
#2  torch::audio::read_audio_file (file_name=..., output=..., nframes=<optimized out>, offset=<optimized out>) at torchaudio/torch_sox.cpp:83
#3  0x00007fffa956b291 in pybind11::detail::argument_loader<std::string const&, at::Tensor, long, long>::call_impl<int, int (*&)(std::string const&, at::Tensor, long, long), 0ul, 1ul, 2ul, 3ul, pybind11::detail::void_type> (f=<optimized out>, this=0x7fffffffd3c0) at /home/kpar/.pyenv/versions/foley/lib/python3.7/site-packages/torch/lib/include/pybind11/cast.h:1919
#4  pybind11::detail::argument_loader<std::string const&, at::Tensor, long, long>::call<int, pybind11::detail::void_type, int (*&)(std::string const&, at::Tensor, long, long)>(int (*&)(std::string const&, at::Tensor, long, long)) && (f=<optimized out>, this=<optimized out>) at /home/kpar/.pyenv/versions/foley/lib/python3.7/site-packages/torch/lib/include/pybind11/cast.h:1896
#5  void pybind11::cpp_function::initialize<int (*&)(std::string const&, at::Tensor, long, long), int, std::string const&, at::Tensor, long, long, pybind11::name, pybind11::scope, pybind11::sibling, char [34]>(int (*&)(std::string const&, at::Tensor, long, long), int (*)(std::string const&, at::Tensor, long, long), pybind11::name const&, pybind11::scope const&, pybind11::sibling const&, char const (&) [34])::{lambda(pybind11::detail::function_call&)#3}::operator()(pybind11::detail::function_call&) const (call=..., __closure=0x0)
    at /home/kpar/.pyenv/versions/foley/lib/python3.7/site-packages/torch/lib/include/pybind11/pybind11.h:154
#6  void pybind11::cpp_function::initialize<int (*&)(std::string const&, at::Tensor, long, long), int, std::string const&, at::Tensor, long, long, pybind11::name, pybind11::scope, pybind11::sibling, char [34]>(int (*&)(std::string const&, at::Tensor, long, long), int (*)(std::string const&, at::Tensor, long, long), pybind11::name const&, pybind11::scope const&, pybind11::sibling const&, char const (&) [34])::{lambda(pybind11::detail::function_call&)#3}::_FUN(pybind11::detail::function_call&) () at /home/kpar/.pyenv/versions/foley/lib/python3.7/site-packages/torch/lib/include/pybind11/pybind11.h:132
#7  0x00007fffa9568875 in pybind11::cpp_function::dispatcher (self=self@entry=0x7ffff7e44990, args_in=args_in@entry=0x7ffff7f04278, kwargs_in=kwargs_in@entry=0x0)
    at /home/kpar/.pyenv/versions/foley/lib/python3.7/site-packages/torch/lib/include/pybind11/pybind11.h:619
#8  0x00005555555c9f57 in _PyMethodDef_RawFastCallKeywords (kwnames=0x0, nargs=140737352321424, args=0x4574c92a0000000c, self=0x7ffff7e44990, method=0x555556aeaef0) at Objects/call.c:690
#9  _PyCFunction_FastCallKeywords (func=func@entry=0x7fffa98ab120, args=args@entry=0x555555b42630, nargs=nargs@entry=4, kwnames=kwnames@entry=0x0) at Objects/call.c:730
#10 0x00005555555b6c4e in call_function (kwnames=0x0, oparg=4, pp_stack=<synthetic pointer>) at Python/ceval.c:4547
#11 _PyEval_EvalFrameDefault (f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:3086
#12 0x0000555555686e0d in PyEval_EvalFrameEx (throwflag=0, f=0x555555b42488) at Python/ceval.c:547
#13 _PyEval_EvalCodeWithName (_co=0x7ffff7e55300, globals=<optimized out>, locals=locals@entry=0x0, args=<optimized out>, argcount=1, kwnames=0x0, kwargs=0x7ffff7f86b78, kwcount=0, kwstep=1,
    defs=0x7ffff7e63ce0, defcount=4, kwdefs=0x0, closure=0x0, name=0x7ffff7f43538, qualname=0x7ffff7f43538) at Python/ceval.c:3923
#14 0x00005555555c9386 in _PyFunction_FastCallKeywords (func=<optimized out>, stack=<optimized out>, nargs=<optimized out>, kwnames=<optimized out>) at Objects/call.c:433
#15 0x00005555555b6d6b in call_function (kwnames=0x0, oparg=<optimized out>, pp_stack=<synthetic pointer>) at Python/ceval.c:4586
#16 _PyEval_EvalFrameDefault (f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:3086
#17 0x0000555555686e0d in PyEval_EvalFrameEx (throwflag=0, f=0x7ffff7f869f8) at Python/ceval.c:547
#18 _PyEval_EvalCodeWithName (_co=_co@entry=0x7ffff7f136f0, globals=globals@entry=0x7ffff7eda0d8, locals=locals@entry=0x7ffff7eda0d8, args=args@entry=0x0, argcount=argcount@entry=0,
    kwnames=kwnames@entry=0x0, kwargs=0x0, kwcount=0, kwstep=2, defs=0x0, defcount=0, kwdefs=0x0, closure=0x0, name=0x0, qualname=0x0) at Python/ceval.c:3923
#19 0x0000555555686f43 in PyEval_EvalCodeEx (closure=0x0, kwdefs=0x0, defcount=0, defs=0x0, kwcount=0, kws=0x0, argcount=0, args=0x0, locals=locals@entry=0x7ffff7eda0d8,
    globals=globals@entry=0x7ffff7eda0d8, _co=_co@entry=0x7ffff7f136f0) at Python/ceval.c:3952
#20 PyEval_EvalCode (co=co@entry=0x7ffff7f136f0, globals=globals@entry=0x7ffff7eda0d8, locals=locals@entry=0x7ffff7eda0d8) at Python/ceval.c:524
#21 0x00005555556c021e in run_mod (arena=0x7ffff7fd4078, flags=0x7ffff7e4eed0, locals=0x7ffff7eda0d8, globals=0x7ffff7eda0d8, filename=0x7ffff7f14e30, mod=<optimized out>) at Python/pythonrun.c:1035
#22 PyRun_StringFlags (flags=0x7ffff7e4eed0, locals=0x7ffff7eda0d8, globals=0x7ffff7eda0d8, start=257, str=0x7ffff7f040a0 "import torchaudio; torchaudio.load('test.mp3')\n") at Python/pythonrun.c:959
#23 PyRun_SimpleStringFlags (command=0x7ffff7f040a0 "import torchaudio; torchaudio.load('test.mp3')\n", flags=flags@entry=0x7fffffffdca0) at Python/pythonrun.c:455
#24 0x00005555555bb250 in pymain_run_command (cf=0x7fffffffdca0, command=<optimized out>) at Modules/main.c:383
#25 pymain_run_python (pymain=0x7fffffffddf0) at Modules/main.c:2514
#26 pymain_main (pymain=pymain@entry=0x7fffffffddf0) at Modules/main.c:2662
#27 0x00005555555bcccb in _Py_UnixMain (argc=<optimized out>, argv=<optimized out>) at Modules/main.c:2697
#28 0x00007ffff7041b97 in __libc_start_main (main=0x5555555ae620 <main>, argc=3, argv=0x7fffffffe028, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffe018)
    at ../csu/libc-start.c:310
#29 0x00005555555b825a in _start ()
(gdb)

Which library is torchaudio consistent with?

Hi, I'm currently updating my torch codebase from using librosa to torchaudio for transforms, to take advantage of the (much) faster stft torch implementation on the GPU. However, running into several occasions where the output from Spectrogram vs. librosa.core._spectrogram, MelSpectrogram vs. librosa.melspectrogram have different results. Does this repo ensure consistency with another python audio library for those transformations? I think it would be good to have consistency with another widely used library. Currently figuring out the correct params to ensure consistency and I can PR something if that sounds useful.

For example:

sound, sample_rate = torchaudio.load('wav_file.wav')
sound = sound
sound_librosa = sound.cpu().numpy().squeeze().T

sample_rate = 16000
n_mels = 40
window_stride = 0.01
window_size = 0.025
hop_length = int(sample_rate * window_stride)
n_fft = int(sample_rate * window_size)

stft_librosa = librosa.stft(y=sound_librosa,
                            hop_length=hop_length,
                            n_fft=n_fft)
spectro_librosa, n_fft = librosa.core.spectrum._spectrogram(y=sound_librosa,
                            hop_length=hop_length,
                            n_fft=n_fft, power=2)
mel_basis = librosa.filters.mel(sample_rate,
                                n_mels=n_mels,
                                n_fft=n_fft,
                                norm=None, # non-standard
                                htk=True) # non-standard
check = np.dot(mel_basis, spectro_librosa)

stft_torch = torch.stft(soundcuda,
                        hop_length=hop_length,
                        n_fft=n_fft,
                        window=window).transpose(1, 2)
spectro_torch = stft_torch.pow(2).sum(-1)
melscale = torchaudio.transforms.MelScale(n_mels=n_mels)
check2 = melscale(check)

#check == check2

The torchaudio MelScale uses the non-default librosa options norm=None, htk=True on librosa.filters.mel (https://librosa.github.io/librosa/_modules/librosa/filters.html#mel). I also removed the default spectrogram normalization at https://github.com/pytorch/audio/blob/master/torchaudio/transforms.py#L198, which is not a librosa option.

There's also functional inconsistencies between the librosa and torchaudio function calls -- librosa returns a spectrogram with librosa.feature.melspectrogram, whereas torchaudio converts the spectrogram to the Db scale.

Consistency between torchvision/torchaudio

When we load a sound file with torchaudio, we get an output Tensor of size (L x C) (L the number of audio frames and C the number of channels).
It's not a better idea to get a Tensor of shape (C x L) ?

Because, with torchvision, when I load an image and I use the function ToTensor, the dimension of the output tensor is (C x H x W) with the channel in first dimension. Is not it more coherent if the output of the load function in torchaudio use a similar output shape to the ToTensor function ?

In this case, the functions LC2CL and BLC2CBL are no longer necessary.

MEL2 gives incorrect output for n_mels=80

The MEL2 transform seems to work fine for n_mels=40, howver n_mels=80 gives artifacts.

n_mels=40

mel_40

n_mels=80

mel_80

import torchaudio
from torchaudio import transforms
import matplotlib.pyplot as plt


def spect_loader(path):
   y, sr = torchaudio.load(path, normalization=True)
   # n_mels = 40
   n_mels = 80

   to_melspec = transforms.Compose([
       transforms.LC2CL(),
       transforms.MEL2(sr, n_mels=n_mels)
   ])
   melspec = to_melspec(y)
   return melspec


if __name__ == '__main__':
   mel = spect_loader("00f0204f_nohash_0.wav")
   plt.matshow(mel[0].numpy().T)
   plt.colorbar()
   plt.savefig("mel.png")
   plt.clf()
   print(mel.shape)

error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode

The following error occurred when running 'setup.py'

running install
running bdist_egg
running egg_info
writing requirements to torchaudio.egg-info/requires.txt
writing torchaudio.egg-info/PKG-INFO
writing top-level names to torchaudio.egg-info/top_level.txt
writing dependency_links to torchaudio.egg-info/dependency_links.txt
reading manifest file 'torchaudio.egg-info/SOURCES.txt'
writing manifest file 'torchaudio.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
copying torchaudio/_ext/th_sox/__init__.py -> build/lib.linux-x86_64-3.5/torchaudio/_ext/th_sox
running build_ext
generating cffi module 'build/temp.linux-x86_64-3.5/torchaudio._ext.th_sox._th_sox.c'
already up-to-date
building 'torchaudio._ext.th_sox._th_sox' extension
gcc -pthread -B /home/amust/anaconda3/envs/python35/compiler_compat -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/amust/anaconda3/envs/python35/lib/python3.5/site-packages/torch/utils/ffi/../../lib/include -I/home/amust/anaconda3/envs/python35/lib/python3.5/site-packages/torch/utils/ffi/../../lib/include/TH -Itorchaudio/src -I/home/amust/anaconda3/envs/python35/include/python3.5m -c build/temp.linux-x86_64-3.5/torchaudio._ext.th_sox._th_sox.c -o build/temp.linux-x86_64-3.5/build/temp.linux-x86_64-3.5/torchaudio._ext.th_sox._th_sox.o
In file included from /home/amust/anaconda3/envs/python35/lib/python3.5/site-packages/torch/utils/ffi/../../lib/include/TH/THVector.h:5:0,
                 from /home/amust/anaconda3/envs/python35/lib/python3.5/site-packages/torch/utils/ffi/../../lib/include/TH/TH.h:12,
                 from build/temp.linux-x86_64-3.5/torchaudio._ext.th_sox._th_sox.c:492:
/home/amust/anaconda3/envs/python35/lib/python3.5/site-packages/torch/utils/ffi/../../lib/include/TH/THMath.h: In function ‘TH_polevl’:
/home/amust/anaconda3/envs/python35/lib/python3.5/site-packages/torch/utils/ffi/../../lib/include/TH/THMath.h:134:3: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
   for (size_t i = 0; i <= len; i++) {
   ^
/home/amust/anaconda3/envs/python35/lib/python3.5/site-packages/torch/utils/ffi/../../lib/include/TH/THMath.h:134:3: note: use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile your code
/home/amust/anaconda3/envs/python35/lib/python3.5/site-packages/torch/utils/ffi/../../lib/include/TH/THMath.h: In function ‘TH_polevlf’:
/home/amust/anaconda3/envs/python35/lib/python3.5/site-packages/torch/utils/ffi/../../lib/include/TH/THMath.h:142:3: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
   for (size_t i = 0; i <= len; i++) {
   ^
/home/amust/anaconda3/envs/python35/lib/python3.5/site-packages/torch/utils/ffi/../../lib/include/TH/THMath.h: In function ‘TH_trigamma’:
/home/amust/anaconda3/envs/python35/lib/python3.5/site-packages/torch/utils/ffi/../../lib/include/TH/THMath.h:260:3: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
   for (int i = 0; i < 6; ++i) {
   ^
/home/amust/anaconda3/envs/python35/lib/python3.5/site-packages/torch/utils/ffi/../../lib/include/TH/THMath.h: In function ‘TH_trigammaf’:
/home/amust/anaconda3/envs/python35/lib/python3.5/site-packages/torch/utils/ffi/../../lib/include/TH/THMath.h:278:3: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
   for (int i = 0; i < 6; ++i) {
   ^
error: command 'gcc' failed with exit status 1

it can not calculate on GPU

I try to make it on GPU,but it can not run, I want to know whether it can work on GPU if I try to revise code?

thank you,author!!!

Change in `F2M`; more docstrings including examples

Hi, I think I could work on these if they seem useful for users/maintainers.

  • in transforms.F2M,

    • The computation of filterbanks (fb) can be move to init() to remove its redundancy.
  • Would more docstrings be useful?

  • Seems like there could be potential -inf or NaN during applying _tlog10() (Example). Perhaps we could make it little more stable?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.