简体   繁体   English

将声音文件导入为 sf 但在 jupyter notebook sf 上给出 NameError

[英]Import soundfile as sf but on jupyter notebook sf gives NameError

I installed Soundfile by pip install soundfile.我通过 pip install soundfile 安装了 Soundfile。 Here is my code:这是我的代码:

import soundfile as sf
def speech_file_to_array_fn(batch):
    speech_array, sampling_rate = sf.read(batch["file"])
    batch["speech"] = speech_array
    batch["sampling_rate"] = sampling_rate
    batch["target_text"] = batch["text"]
    return batch

timit = timit.map(speech_file_to_array_fn, remove_columns=timit.column_names["train"], num_proc=4)

but it gives an NameError.但它给出了一个 NameError。 NameError: name 'sf' is not defined NameError:名称“sf”未定义

I could not see the problem, I work on jupyter notebook.我看不到问题,我在 jupyter notebook 上工作。

Downgrading to version 0.10.2 solved to issue for me (pip install SoundFile==0.10.2).降级到版本 0.10.2 解决了我的问题(pip install SoundFile==0.10.2)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM