Skip to main content
 首页 » 编程设计

python之pocketsphinx python 给出错误的时间戳

2025年02月15日13daizhj

我正在使用 pocketsphinx 将音频转换为文本。它工作正常。现在我想获取每个单词的时间戳。这是我的代码:

import speech_recognition as sr 
 
r = sr.Recognizer() 
framerate = 100 
with sr.AudioFile("1.wav") as source: 
 
    audio = r.record(source) 
 
    decoder = r.recognize_sphinx(audio, show_all=False) 
 
    print ([(seg.word, seg.start_frame/framerate)for seg in decoder.seg()]) 

根据他们的文档,默认帧率为 100。我得到了每个单词的开始时间。但是,这是不正确的。相差2秒,有时甚至超过3秒。

这是已知问题还是我遗漏了什么?

请您参考如下方法:

我在某处读到比率是 1/100 因此,在我的项目中,我不小心将 1/10 而不是 1/100 但结果实际上对我所做的来说还不错。我建议除以 0.1 或 0.01,看看能为您提供什么。

因此对于您的代码,只需尝试这些变量:

framerate = .1  

或

framerate = .01