You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何正确使用whisper_timestamped的transcribe方法?运行报错求解决

解决whisper-timestamped调用transcribe时的AttributeError问题

问题场景

使用whisper-timestamped的transcribe方法对example.mp3生成带时间戳的转录结果,调用时报错:

AttributeError: 'NoneType' object has no attribute 'shape'

报错出现在whisper_timestamped/transcribe.py的hook_attention_weights函数中,提示变量w为None,无法获取shape属性。已尝试重新安装相关包,但问题未解决。

解决方案

1. 调整版本兼容性

whisper-timestamped与OpenAI Whisper的版本匹配是核心问题,部分新版本Whisper会修改模型输出结构,导致旧版whisper-timestamped无法正常解析注意力权重。执行以下命令安装兼容版本:

pip uninstall -y whisper whisper_timestamped
pip install openai-whisper==20231117 whisper-timestamped==1.15.0

2. 修正转录参数

CPU设备不支持半精度(fp16)计算,需在transcribe时显式关闭该选项:

result = whisper.transcribe(model, audio, language="en", fp16=False)

同时确认example.mp3路径正确,建议使用绝对路径避免路径问题:

audio = whisper.load_audio('/full/path/to/example.mp3')

3. 测试小尺寸模型

尝试使用更小的模型(如tiny)验证是否为模型尺寸导致的兼容问题:

model = whisper.load_model("tiny", device="cpu")

完整示例代码

import whisper_timestamped as whisper
import json

# 使用绝对路径加载音频
audio = whisper.load_audio('/full/path/to/example.mp3')

# 加载兼容版本的small模型
model = whisper.load_model("small", device="cpu")

# 关闭fp16并执行转录
result = whisper.transcribe(model, audio, language="en", fp16=False)

print(json.dumps(result, indent=2, ensure_ascii=False))

内容的提问来源于stack exchange,提问作者Luka Varsimashvili

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 05:33:11