python mel() takes 0 positional arguments but 2 positional arguments (and 3 keyword-only arguments) were given
2025-06-09 20:43:55
调试过程中,发生报错:
Wav2Lip失败: Traceback (most recent call last): File "E:pythoncodeideoWav2Lipinference.py", line 280, in main() File "E:pythoncodeideoWav2Lipinference.py", line 225, in main mel = audio.melspectrogram(wav) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:pythoncodeideoWav2Lipudio.py", line 47, in melspectrogram S = _amp_to_db(_linear_to_mel(np.abs(D))) - hp.ref_level_db ^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:pythoncodeideoWav2Lipudio.py", line 95, in _linear_to_mel _mel_basis = _build_mel_basis() ^^^^^^^^^^^^^^^^^^ File "E:pythoncodeideoWav2Lipudio.py", line 100, in _build_mel_basis return librosa.filters.mel(hp.sample_rate, hp.n_fft, n_mels=hp.num_mels, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: mel() takes 0 positional arguments but 2 positional arguments (and 3 keyword-only arguments) were given
错误信息是:
TypeError: mel() takes 0 positional arguments but 2 positional arguments (and 3 keyword-only arguments) were given
出现这个问题,是因为Wav2Lip 的 audio.py
代码调用 librosa.filters.mel
的参数格式已不兼容新版本 librosa。
- 新版
librosa
(0.10.x及以上)中,mel()
函数的参数签名和老版不同。 - 你的代码是按照旧版本
librosa
写的,所以新版就会报参数不匹配的错。
解决方法
1. 卸载新版 librosa,安装兼容的旧版本(推荐)
在命令行运行:
bash
复制
python -m pip uninstall librosa
python -m pip install librosa==0.7.0
Wav2Lip 推荐用 librosa 0.7.0 或 0.8.0。
2. 检查requirements.txt
中librosa的版本
如果你有 requirements.txt
,建议把其中的 librosa 行替换成:
复制
librosa==0.7.0
重启你的 Flask 服务,再次测试. 问题解决。
发表评论: