如何在 OpenAI 的 Whisper ASR 中获取字级时间戳?

Fra*_*urt 15 python speech-recognition timestamp openai-api openai-whisper

我使用 OpenAI 的Whisper python 库进行语音识别。如何获取字级时间戳?


使用 OpenAI 的Whisper进行转录(在 Ubuntu 20.04 x64 LTS 上使用 Nvidia GeForce RTX 3090 进行测试):

conda create -y --name whisperpy39 python==3.9
conda activate whisperpy39
pip install git+https://github.com/openai/whisper.git 
sudo apt update && sudo apt install ffmpeg
whisper recording.wav
whisper recording.wav --model large
Run Code Online (Sandbox Code Playgroud)

如果使用 Nvidia GeForce RTX 3090,请在后面添加以下内容conda activate whisperpy39

pip install -f https://download.pytorch.org/whl/torch_stable.html
conda install pytorch==1.10.1 torchvision torchaudio cudatoolkit=11.0 -c pytorch
Run Code Online (Sandbox Code Playgroud)

小智 13

我创建了一个存储库来恢复字级时间戳(和置信度),以及更准确的段时间戳: https ://github.com/Jeronymous/whisper-timestamped

它是基于 Whisper 的交叉注意力权重构建的,如Whisper 存储库中的笔记本所示。我稍微调整了方法以获得更好的位置,并添加了动态获得交叉注意力的可能性,因此无需运行 Whisper 模型两次。处理长音频时不存在内存问题。

注意:首先,我尝试了使用 wav2vec 模型来重新对齐 Whisper 转录的单词以输入音频的方法。它工作得相当好,但有很多缺点:它需要处理一个单独的 (wav2vec) 模型,对完整信号执行另一个推理,每种语言有一个 wav2vec 模型,规范化转录文本,以便字符集适合 wav2vec 模型之一(例如将数字转换为字符、“%”等符号、货币...)。此外,对齐可能会遇到通常由 Whisper 消除的不流畅问题(因此缺少识别 wav2vec 模型的部分内容,例如重新表述的句子开头)。


Fra*_*urt 8

https://openai.com/blog/whisper/只提到“短语级时间戳”,我从中推断,如果不添加更多代码,就无法获得单词级时间戳。

来自《耳语》作者之一

不直接支持获取单词级时间戳,但可以使用时间戳标记或交叉注意力权重的预测分布。

https://github.com/jianfch/stable-ts(麻省理工学院许可证):

该脚本修改了 Whisper 模型的方法,以获取每个单词的预测时间戳标记,而无需额外的推理。它还将时间戳稳定到字级别,以确保时间顺序。

注意:


另一种选择:使用一些字级强制对齐程序。例如, Lhotse(Apache-2.0 许可证)集成了Whisper ASR 和 Wav2vec 强制对齐:

在此输入图像描述


Gas*_*rdP 2

openai-whisper版本中20231117,您可以通过word_timestamps=True调用时设置来获取字级时间戳transcribe()

pip install openai-whisper
Run Code Online (Sandbox Code Playgroud)
pip install openai-whisper
Run Code Online (Sandbox Code Playgroud)

印刷:

托托,[2.98/3.4]我[3.4/3.82]有[3.82/3.96]一种[3.96/4.02]感觉[4.02/4.22]我们是[4.22/4.44]不是[4.44/4.56]在[4.56/4.72] ] 堪萨斯[4.72/5.14] 不再。[5.14/5.48]