Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

35
LINES

< > BotCompany Repo | #1026985 // recognize.py (vosk)

Document

1  
#!/usr/bin/python3
2  
3  
from vosk import Model, KaldiRecognizer
4  
import sys
5  
import json
6  
import os
7  
8  
if not os.path.exists(sys.argv[1]):
9  
    print ("Please download the model from https://github.com/alphacep/kaldi-android-demo/releases and unpack as 'model' in the current folder.")
10  
    exit (1)
11  
12  
model = Model(sys.argv[1])
13  
14  
# Large vocabulary free form recognition
15  
rec = KaldiRecognizer(model, 16000)
16  
17  
# You can also specify the possible word list
18  
#rec = KaldiRecognizer(model, 16000, "zero oh one two three four five six seven eight nine")
19  
20  
wf = open(sys.argv[2], "rb")
21  
wf.read(44) # skip header
22  
23  
while True:
24  
    data = wf.read(2000)
25  
    if len(data) == 0:
26  
        break
27  
    if rec.AcceptWaveform(data):
28  
        res = json.loads(rec.Result())
29  
        print (res)
30  
    else:
31  
        res = json.loads(rec.PartialResult())
32  
        print (res)
33  
34  
res = json.loads(rec.FinalResult())
35  
print (res)

download  show line numbers   

Travelled to 8 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, snaazhdonpnp, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1026985
Snippet name: recognize.py (vosk)
Eternal ID of this version: #1026985/1
Text MD5: 5a5a8aa6739017f843f5c63a56669d22
Author: stefan
Category: javax / audio recognition
Type: Document
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-02-06 02:28:33
Source code size: 916 bytes / 35 lines
Pitched / IR pitched: No / No
Views / Downloads: 327 / 185
Referenced in: [show references]