alphacep / alphacep/vosk-api

test_gradio.py with vosk not working

Open
#1,214 9 comments 0 reactions 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
15.1k
Forks
1.8k
PR merge metrics
No merged PRs in 30d

Description

Hello,
I want to present vosk on the gradio service using the Turkish model, but I could not achieve this.

I can run the code but it doesn't write anything on the gradio screen.

When I examine the code a bit, I can actually get the sound in bytes, but rec.Result returns empty.
*******************************************************
('\n ', (, []))
***********************************************************************
i am making the sample code with you can you help please;

```
import json
import gradio as gr

from vosk import KaldiRecognizer, Model

model = Model(r"C:\Users\Administrator\PycharmProjects\vosk\model\vosk-model-small-tr-0.3\vosk-model-small-tr-0.3")

def transcribe(data, state):
sample_rate, audio_data = data
audio_data = (audio_data >> 16).astype("int16").tobytes()

if state is None:
rec = KaldiRecognizer(model, sample_rate)
result = []
else:
rec, result = state

if rec.AcceptWaveform(audio_data):
text_result = json.loads(rec.Result())["text"]
if text_result != "":
result.append(text_result)
partial_result = ""
else:
partial_result = json.loads(rec.PartialResult())["partial"] + " "

return "\n".join(result) + "\n" + partial_result, (rec, result)

gr.Interface(
fn=transcribe,
inputs=[
gr.Audio(source="microphone", type="numpy", streaming=True),
"state"
],
outputs=[
"textbox",
"state"
],
live=True).launch(share=True)
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.