在安装了 PyTorch 的 Anaconda Python 3.6.7 中,在 Windows 10 上,我执行以下序列:
conda install -c conda-forge librosa
conda install -c groakat sox
然后从 https://github.com/pytorch/audio 重新下载我愿意
python setup.py install
它运行了一段时间并像这样结束:
torchaudio/torch_sox.cpp(3): fatal error C1083: Cannot open include file: 'sox.h': No such file or directory
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.15.26726\\bin\\HostX86\\x64\\cl.exe' failed with exit status 2
我正在尝试在 Windows 上重现此 OpenNMT-py 语音训练演示:http://opennmt.net/OpenNMT-py/speech2text.html
最佳答案
我成功地在 Windows 10 中使用 sox 编译了 torchaudio,但是有点棘手。
不幸的是,sox_effects 不可用,出现此错误:
RuntimeError: Error opening output memstream/temporary file
但您可以使用其他 torchaudio 功能。
我针对 Windows 10 64 位执行的步骤是:
TORCHAUDIO WINDOWS10 64位
注意:我混合了一些类似于unix的命令行语法,你可以使用文件资源管理器或其他
初步安排
- 下载 sox 源
$ git clone git://git.code.sf.net/p/sox/code sox
- 下载其他sox源码获取lpc10
$ git clone https://github.com/chirlu/sox/tree/master/lpc10 sox2
$ cp -R sox2/lpc10 sox
- 重要的是安装 VisualStudio2019 和 BuildTools
lpc10 库
4.0。为 lpc10 创建 VisualStudio CMake 项目并构建它
Start window -> open local folder -> sox/lpc10
(it reads CMakeLists.txt automatically)
Build->build All
4.2。将lpc10.lib复制到sox
$ mkdir -p sox/src/out/build/x64-Debug
$ cp sox/lpc10/out/build/x64-Debug/lpc10.lib sox/src/out/build/x64-Debug
gsm 库
5.0。为 libgsm 创建一个 CMake 项目,并像以前一样使用 lpc10 进行编译
5.1。将gsm.lib复制到sox
$ mkdir -p sox/src/out/build/x64-Debug
$ cp sox/libgsm/out/build/x64-Debug/gsm.lib sox/src/out/build/x64-Debug
sox 库
6.0。在VS中创建sox的CMake项目
6.1。编辑一些文件:
CMakeLists.txt:(在最开始添加)
project(sox)
sox_i.h:(在stdlib.h包含行下添加)
#include <wchar.h> /* For off_t not found in stdio.h */
#define UINT16_MAX ((int16_t)-1)
#define INT32_MAX ((int32_t)-1)
sox.c:(在 time.h 包含行下添加)
`#include <sys/timeb.h>`
6.2。使用 VisualStudio 构建 sox
6.3。复制 python 可以找到的库,我使用 conda 环境:
$ cp sox/src/out/build/x64-Debug/libsox.lib envs\<envname>\libs\sox.lib
$ cp sox/src/out/build/x64-Debug/gsm.lib envs\<envname>\libs
$ cp sox/src/out/build/x64-Debug/lpc10.lib envs\<envname>\libs
torch 音频
$ activate <envname>
7.0。从github下载torchaudio
$ git clone https://github.com/pytorch/audio thaudio
7.1。更新 setup.py,在“if IS_WHEEL...”的“else:”语句之后
$ vi thaudio/setup.py
如果 IS_WHEEL...
else:
audio_path = os.path.dirname(os.path.abspath(__file__))
# Add include path for sox.h, I tried both with the same outcome
include_dirs += [os.path.join(audio_path, '../sox/src')]
#include_dirs += [os.path.join(audio_path, 'torchaudio/sox')]
# Add more libraries
#libraries += ['sox']
libraries += ['sox','gsm','lpc10']
7.2。从 torchaudio 编辑 sox.cpp,因为不允许使用动态数组:
$ vi thaudio/torchaudio/torch_sox.cpp
//char* sox_args[max_num_eopts];
char* sox_args[20]; //Value of MAX_EFFECT_OPTS
7.3。构建并安装
$ cd thaudio
$ python setup.py install
它将打印出大量有关类型转换的警告以及一些与 MSVCRTD 冲突的库,但“有效”。
仅此而已。
关于python - 如何在 Windows 10 conda 上安装 torch 音频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54872876/