How can I get the timing for each word using vosk

574 views
Skip to first unread message

Srikanth

unread,
Jan 5, 2022, 12:24:59 PM1/5/22
to kaldi-help
Hi there, I have seen vosk tutorial printing out the timing for each word but when the same script I use I can't see any timings and I didn't find anything related to timing in the script. what is the parameter specific to print out timing?

#!/usr/bin/env python3

from vosk import Model, KaldiRecognizer, SetLogLevel
import vosk
import sys
import os
import wave
import subprocess

SetLogLevel(0)

if not os.path.exists("model"):
print ("Please download the model from https://alphacephei.com/vosk/models and unpack as 'model' in the current folder.")
exit (1)

sample_rate=16000
model = Model("model")
rec = KaldiRecognizer(model, sample_rate)

process = subprocess.Popen(['ffmpeg', '-loglevel', 'quiet', '-i',
sys.argv[1],
'-ar', str(sample_rate) , '-ac', '1', '-f', 's16le', '-'],
stdout=subprocess.PIPE)

while True:
data = process.stdout.read(4000)
if len(data) == 0:
break
if rec.AcceptWaveform(data):
print(rec.Result())
else:
print(rec.PartialResult())

print(rec.FinalResult())

Thanks 

Khawaja Ali Hassan

unread,
Jan 5, 2022, 12:49:18 PM1/5/22
to kaldi...@googlegroups.com
Did you the unzip the model and place the model in the right directory.?

--
Go to http://kaldi-asr.org/forums.html to find out how to join the kaldi-help group
---
You received this message because you are subscribed to the Google Groups "kaldi-help" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kaldi-help+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kaldi-help/78a5fe4e-94d0-49cf-ae29-91355806bb32n%40googlegroups.com.

nshm...@gmail.com

unread,
Jan 5, 2022, 2:49:25 PM1/5/22
to kaldi-help
You'd better ask on github.

You need to add rec.SetWords(True) after constructor to enable timings

Srikanth

unread,
Jan 6, 2022, 10:47:00 PM1/6/22
to kaldi-help
I have tried the option you said by adding rec.SetWords(True) but it printed None in the output 

{
  "text" : "प्रिय ग्राहक अभाव अपने लोन एप का उपयोग करके पेमेंट कर सकते हैं यह आप हमारी चाटबोट् सेवा का उपयोग कर सकते हैं हमारी चैट बहुत सेवा का उपयोग करने के लिए बस हमारी वेबसाइट डब्ल्यूडब्ल्यूडब्ल्यू डॉट डीएमआई फैनेंस डॉट इन पर जाए और हेलो डीएमआई चार पर क्लिक करें आप"
} None


while True:
data = process.stdout.read(4000)
if len(data) == 0:
break
if rec.AcceptWaveform(data):
print(rec.Result(),rec.SetWords(True))
else:
print(rec.PartialResult())

print(rec.FinalResult())

Reply all
Reply to author
Forward
0 new messages