alphacep / vosk-api

Offline speech recognition API for Android, iOS, Raspberry Pi and servers with Python, Java, C# and Node
Apache License 2.0
7.58k stars 1.06k forks source link

Failed to process waveform #965

Closed RD0617 closed 2 years ago

RD0617 commented 2 years ago

Hello everyone! When i try to run the basic example of code I get an error

Traceback (most recent call last):
  File "C:\Users\Ruslan\Desktop\vosk-model-small-en-us-0.15\v.py", line 22, in <module>
    print(rec.Result() if rec.AcceptWaveform(data) else rec.PartialResult())
  File "C:\Users\Ruslan\AppData\Local\Programs\Python\Python38\lib\site-packages\vosk\__init__.py", line 78, in AcceptWaveform
    raise Exception("Failed to process waveform")
Exception: Failed to process waveform

Code:

from vosk import Model, KaldiRecognizer
import os
import pyaudio

model = Model(r"model")
rec = KaldiRecognizer(model, 8000)
p = pyaudio.PyAudio()
stream = p.open(
    format=pyaudio.paInt16, 
    channels=1, 
    rate=8000, 
    input=True, 
    frames_per_buffer=8000
)
stream.start_stream()

while True:
    data = stream.read(4000)
    if len(data) == 0:
        break

    print(rec.Result() if rec.AcceptWaveform(data) else rec.PartialResult())

print(rec.FinalResult())

What is the problem?

nshmyrev commented 2 years ago

We recommend to use sounddevice instead of pyaudio:

https://github.com/alphacep/vosk-api/blob/master/python/example/test_microphone.py

nshmyrev commented 2 years ago

Let us know if you need extra help

iamvibhavtripathi commented 5 months ago

i am also facing the same issue:- from vosk import Model,KaldiRecognizer import pyaudio

model= Model("/Users/jaihanuman/Desktop/untitled folder/task/vosk/vosk-model-small-en-us-0.15 2") rec= KaldiRecognizer(model,1600)

mic= pyaudio.PyAudio() stream =mic.open(rate=16000, channels=1, format=pyaudio.paInt16,input=True,frames_per_buffer=8192) stream.start_stream()

while True: data = stream.read(4096)

if len(data) ==0:

#     break

if recognizer.AcceptWaveform(data):
    print(recognizer.Result())

print(rec.Result() if rec.AcceptWaveform(data) else rec.PartialResult())

print(rec.FinalResult())

this is the code and heres the error :-

if recognizer.AcceptWaveform(data): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/anaconda3/lib/python3.11/site-packages/vosk/init.py", line 184, in AcceptWaveform raise Exception("Failed to process waveform") Exception: Failed to process waveform

how ti resolve?

nshmyrev commented 5 months ago

@iamvibhavtripathi

  1. follow our examples
  2. learn to format code on github properly