0%

Speechbrain Windows 笔记

前言

本篇记录一下 speechbrain 的安装使用过程。在 Windows 10 环境。 放弃了,PyTorch 对于 Windows 的支持性导致 speechbrain 的使用非常麻烦。转 Linux 再说吧。

新环境没有安装博客相关的东西,下面列一下要新安装的软件。(其实应该单列一个博客的……)

再次安装 CUDA https://developer.nvidia.com/cuda-zone,安装包的下载速度与安装速度都还可以接受。

安装了 Anaconda3. https://mirrors.tuna.tsinghua.edu.cn/#

再次安装 PyTorch https://pytorch.org/get-started/locally/,使用 conda,即使换了国内源,也非常非常非常慢……

安装 speechbrain https://github.com/speechbrain/speechbrain ,这个库似乎没有说支持 Windows……但是我全程在 Windows 测试,踩坑试试。

正文

一顿操作猛如虎,安装完 speechbrain 以后其实还是要 clone 一下这个 repo,来做测试。

来自后文的警告:别忘了开管理员权限,好不容易跑通,结果后面说要创建临时文件,没有权限给挂了。

1
2
3
4
5
6
7
git clone https://github.com/speechbrain/speechbrain.git
# 顺便下载一个说话人识别的预训练模型
git lfs install
git clone https://huggingface.co/speechbrain/spkrec-ecapa-voxceleb
# 接下来按照官方 repo 的 readme,做测试。
cd .\speechbrain\
pytest tests

然后疯狂报错,光是 import speechbrain 就在疯狂调bug。

第一个错类似下面。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
ImportError while importing test module 'C:\Users\***\projects\speechbrain\speechbrain\tests\integration\neural_networks\ASR_CTC\example_asr_ctc_experiment.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
..\..\..\anaconda3\lib\importlib\__init__.py:127: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
tests\integration\neural_networks\ASR_CTC\example_asr_ctc_experiment.py:11: in <module>
import speechbrain as sb
speechbrain\__init__.py:4: in <module>
from .core import Stage, Brain, create_experiment_directory, parse_arguments
speechbrain\core.py:31: in <module>
from hyperpyyaml import resolve_references
..\..\..\anaconda3\lib\site-packages\hyperpyyaml\__init__.py:7: in <module>
from .core import (
..\..\..\anaconda3\lib\site-packages\hyperpyyaml\core.py:17: in <module>
import ruamel.yaml
E ModuleNotFoundError: No module named 'ruamel'

找不到 ruamel。其实这个包是有的,叫 ruamel.yaml。但是似乎是因为 pip 和 conda 的一些问题,调不到。如果是纯 pip 环境似乎没有这个问题。

参考 https://stackoverflow.com/questions/41373834/conda-importerror-no-module-named-ruamel-yaml-comments

Try conda install ruamel.yaml … pip didnt work for me

执行这一条命令后,问题解决。

第二个问题类似下面这样。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
E   RuntimeError: Backend "soundfile" is not one of available backends: [].
_____________________________________________________________________________________________________ ERROR collecting tests/unittests/test_augment.py _____________________________________________________________________________________________________
tests\unittests\test_augment.py:3: in <module>
from speechbrain.dataio.dataio import write_audio
speechbrain\__init__.py:4: in <module>
from .core import Stage, Brain, create_experiment_directory, parse_arguments
speechbrain\core.py:32: in <module>
from speechbrain.utils.distributed import run_on_main
speechbrain\utils\__init__.py:11: in <module>
from . import * # noqa
speechbrain\utils\Accuracy.py:7: in <module>
from speechbrain.dataio.dataio import length_to_mask
speechbrain\dataio\__init__.py:11: in <module>
from . import * # noqa
speechbrain\dataio\dataio.py:26: in <module>
torchaudio.set_audio_backend(torchaudio_backend)
..\..\..\anaconda3\lib\site-packages\torchaudio\backend\utils.py:52: in set_audio_backend
raise RuntimeError(
E RuntimeError: Backend "soundfile" is not one of available backends: [].

查了一下,这个问题不是 speechbrain 的问题,是 torchaudio 报出的问题。

https://stackoverflow.com/questions/62543843/cannot-import-torch-audio-no-audio-backend-is-available

You need to install the audio file I/O backend. If Linux it’s Sox, if Windows it’s SoundFile

To check if you have one set run str(torchaudio.get_audio_backend()) and if ‘None’ is the result then install the backend.

SoundFile for Windows pip install PySoundFile

Sox for Linux pip install sox

之后似乎没有问题了,只有 warning。(无视 warning 程序员传统艺能),输出贴在下面以供对比参考了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
(base) PS C:\users\xxxxx\projects\speechbrain\speechbrain> pytest tests
================================================= test session starts =================================================
platform win32 -- Python 3.8.5, pytest-6.1.1, py-1.9.0, pluggy-0.13.1
rootdir: C:\users\xxxxx\projects\speechbrain\speechbrain, configfile: pytest.ini
collected 109 items

tests\integration\neural_networks\ASR_CTC\example_asr_ctc_experiment.py . [ 0%]
tests\integration\neural_networks\ASR_CTC\example_asr_ctc_experiment_complex_net.py . [ 1%]
tests\integration\neural_networks\ASR_CTC\example_asr_ctc_experiment_quaternion_net.py . [ 2%]
tests\integration\neural_networks\ASR_DNN_HMM\example_asr_dnn_hmm_experiment.py . [ 3%]
tests\integration\neural_networks\ASR_Transducer\example_asr_transducer_experiment.py . [ 4%]
tests\integration\neural_networks\ASR_alignment_forward\example_asr_alignment_forward_experiment.py . [ 5%]
tests\integration\neural_networks\ASR_alignment_viterbi\example_asr_alignment_viterbi_experiment.py . [ 6%]
tests\integration\neural_networks\ASR_seq2seq\example_asr_seq2seq_experiment.py . [ 7%]
tests\integration\neural_networks\G2P\example_g2p.py . [ 8%]
tests\integration\neural_networks\LM_RNN\example_lm_rnn_experiment.py . [ 9%]
tests\integration\neural_networks\VAD\example_vad.py . [ 10%]
tests\integration\neural_networks\autoencoder\example_auto_experiment.py . [ 11%]
tests\integration\neural_networks\enhance_GAN\example_enhance_gan_experiment.py . [ 11%]
tests\integration\neural_networks\separation\example_conv_tasnet.py . [ 12%]
tests\integration\neural_networks\speaker_id\example_xvector_experiment.py . [ 13%]
tests\integration\signal_processing\example_add_babble.py . [ 14%]
tests\integration\signal_processing\example_add_noise.py . [ 15%]
tests\integration\signal_processing\example_add_reverb.py . [ 16%]
tests\integration\signal_processing\example_do_clip.py . [ 17%]
tests\integration\signal_processing\example_drop_chunk.py . [ 18%]
tests\integration\signal_processing\example_drop_freq.py . [ 19%]
tests\integration\signal_processing\example_speed_perturb.py . [ 20%]
tests\integration\signal_processing\PLDA_xvector\example_plda_experiment.py . [ 21%]
tests\integration\signal_processing\nmf_sourcesep\example_experiment.py . [ 22%]
tests\unittests\test_CNN.py ... [ 24%]
tests\unittests\test_RNN.py . [ 25%]
tests\unittests\test_activations.py . [ 26%]
tests\unittests\test_arpa.py .. [ 28%]
tests\unittests\test_augment.py ....... [ 34%]
tests\unittests\test_batching.py ... [ 37%]
tests\unittests\test_callchains.py .. [ 39%]
tests\unittests\test_categorical_encoder.py ..... [ 44%]
tests\unittests\test_checkpoints.py ...... [ 49%]
tests\unittests\test_core.py .. [ 51%]
tests\unittests\test_counting.py ... [ 54%]
tests\unittests\test_data_io.py .. [ 55%]
tests\unittests\test_data_pipeline.py ... [ 58%]
tests\unittests\test_dataloader.py .. [ 60%]
tests\unittests\test_dataset.py .. [ 62%]
tests\unittests\test_dependency_graph.py . [ 63%]
tests\unittests\test_dropout.py . [ 64%]
tests\unittests\test_edit_distance.py .... [ 67%]
tests\unittests\test_embedding.py . [ 68%]
tests\unittests\test_epoch_loop.py . [ 69%]
tests\unittests\test_features.py ...... [ 75%]
tests\unittests\test_linear.py . [ 76%]
tests\unittests\test_losses.py ....... [ 82%]
tests\unittests\test_metrics.py ..... [ 87%]
tests\unittests\test_multi_mic.py . [ 88%]
tests\unittests\test_ngram_lm.py . [ 88%]
tests\unittests\test_normalization.py ..... [ 93%]
tests\unittests\test_pooling.py .. [ 95%]
tests\unittests\test_pretrainer.py . [ 96%]
tests\unittests\test_samplers.py . [ 97%]
tests\unittests\test_schedulers.py . [ 98%]
tests\unittests\test_signal_processing.py . [ 99%]
tests\unittests\test_tokenizer.py . [100%]

================================================== warnings summary ===================================================
..\..\..\anaconda3\lib\site-packages\pyreadline\py3k_compat.py:8
C:\Users\xxxxx\anaconda3\lib\site-packages\pyreadline\py3k_compat.py:8: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.9 it will stop working
return isinstance(x, collections.Callable)

..\..\..\anaconda3\lib\site-packages\win32\lib\pywintypes.py:2
C:\Users\xxxxx\anaconda3\lib\site-packages\win32\lib\pywintypes.py:2: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
import imp, sys, os

..\..\..\anaconda3\lib\site-packages\torchaudio\extension\extension.py:13
C:\Users\xxxxx\anaconda3\lib\site-packages\torchaudio\extension\extension.py:13: UserWarning: torchaudio C++ extension is not available.
warnings.warn('torchaudio C++ extension is not available.')

tests/unittests/test_RNN.py::test_RNN
C:\Users\xxxxx\anaconda3\lib\site-packages\torch\nn\modules\rnn.py:201: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
if self.input_size != input.size(-1):

tests/unittests/test_RNN.py::test_RNN
C:\Users\xxxxx\anaconda3\lib\site-packages\torch\nn\modules\rnn.py:222: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
if hx.size() != expected_hidden_size:

tests/unittests/test_normalization.py::test_BatchNorm1d
tests/unittests/test_normalization.py::test_BatchNorm2d
tests/unittests/test_normalization.py::test_InstanceNorm1d
tests/unittests/test_normalization.py::test_InstanceNorm2d
C:\Users\xxxxx\anaconda3\lib\site-packages\torch\nn\functional.py:2113: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
if size_prods == 1:

-- Docs: https://docs.pytest.org/en/stable/warnings.html
===================================== 109 passed, 9 warnings in 279.73s (0:04:39) =====================================

测试通过,但是实际使用还是会有问题,因为 PyTorch Audio 不支持 Windows。