#!/usr/bin/env python3
from vosk import Model, KaldiRecognizer, SetLogLevel
import sys
import os
import wave
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)
wf = wave.open("3.wav", "rb")
if wf.getnchannels() != 1 or wf.getsampwidth() != 2 or wf.getcomptype() != "NONE":
print ("Audio file must be WAV format mono PCM.")
exit (1)
model = Model("model")
rec = KaldiRecognizer(model, wf.getframerate())
num = 0
while True:
data = wf.readframes(256)
# print(data)
if len(data) == 0:
break
if rec.AcceptWaveform(data):
print(rec.Result())
else:
print("第{}贞".f
离线语音识别,vosk,离线流式实时静音噪声监测,支持多语言开发python c++ c# java等...
最新推荐文章于 2024-08-08 08:29:27 发布