import speech_recognition as sr
r = sr.Recognizer()
framerate = 100
with sr.AudioFile("transcript.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()])
我遇到以下错误:
文件“ C:/用户/ KUMAR /下载/untitled2.py”,第11行,在 打印([[[seg.word,seg.start_frame / framerate)for reader.seg()中的段])
AttributeError:'str'对象没有属性'seg'
该如何解决?
答案 0 :(得分:0)
首先,感谢您将我指向speech_recognition库。我不知道它的存在,可能会有用。
我看到您有show_all=False
,但是docs说要获得Decoder
对象,它必须为True,因此它只是将转录作为字符串返回。
这是摘录
如果show_all为false,则返回最可能的转录( 默认)。否则,返回狮身人面像 pocketsphinx.pocketsphinx.Decoder对象由 识别。