简体   繁体   English

异常:处理波形失败

[英]Exception: Failed to process waveform

Error:错误:

Traceback (most recent call last):
  File "c:\Programming\New_assistant\speech_to_text.py", line 18, in <module>
    if rec.AcceptWaveform(data):
  File "C:\Users\david\AppData\Local\Programs\Python\Python310\lib\site-packages\vosk\__init__.py", line 84, in AcceptWaveform
    raise Exception("Failed to process waveform")
Exception: Failed to process waveform
PS C:\Programming\New_assistant> 

I get this error when I try to use AcceptWaveform regardless of the file (wav) or the rest of the code, but the error is removed only when using vosk-model-small-ru-0.22, and does not give errors on vosk-model-ru-0.22, but the processing time is too long.无论文件(wav)或其余代码如何,当我尝试使用 AcceptWaveform 时都会出现此错误,但仅在使用 vosk-model-small-ru-0.22 时才会删除该错误,并且不会在 vosk- 上给出错误model-ru-0.22,但处理时间太长。

Code:代码:

from vosk import Model, KaldiRecognizer
import json
import wave

model = Model(r"File\vosk-model-small-ru-0.22")

wf = wave.open(r"File\record1.wav", "rb")
rec = KaldiRecognizer(model, 8000)

result = ''
last_n = False

while True:
    data = wf.readframes(8000)
    if len(data) == 0:
        break

    if rec.AcceptWaveform(data):
        res = json.loads(rec.Result())

        if res['text'] != '':
            result += f" {res['text']}"
            last_n = False
        elif not last_n:
            result += '\n'
            last_n = True

res = json.loads(rec.FinalResult())
result += f" {res['text']}"

print(result)

Using the poke method, I found a solution and got an assumption about the error occurring, so if I'm wrong or you have a more complete solution, add it and I'll mark it.使用 poke 方法,我找到了一个解决方案,并对发生的错误进行了假设,所以如果我错了或者您有更完整的解决方案,请添加它,我会标记它。

If you copied the sample code using vosk, then most likely this is the version with the module vosk-model-ru-0.22 which works with the sampling rate 8000,but vosk-model-small-ru-0.22 works with 44100, so just change 8000 to 44100 (depending on the entry)如果您使用 vosk 复制示例代码,那么很可能这是带有模块 vosk-model-ru-0.22 的版本,它适用于采样率 8000,但 vosk-model-small-ru-0.22 适用于 44100,所以只需将 8000 更改为 44100(取决于条目)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM