Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- import wave
- from pathlib import Path
- from vosk import Model, KaldiRecognizer
- from audio_convert import to_wav
- MODEL_PATH = "model" # <-- укажи здесь путь к модели
- def transcribe(audio_path):
- wav_path = to_wav(audio_path)
- model = Model(MODEL_PATH)
- with wave.open(str(wav_path), "rb") as wf:
- rec = KaldiRecognizer(model, wf.getframerate())
- result = []
- while True:
- data = wf.readframes(4000)
- if not data:
- break
- if rec.AcceptWaveform(data):
- result.append(json.loads(rec.Result())["text"])
- result.append(json.loads(rec.FinalResult())["text"])
- return " ".join(result)
- if __name__ == "__main__":
- audio_file = "audio.mp3" # <-- укажи файл
- text = transcribe(audio_file)
- print(text)
Advertisement
Add Comment
Please, Sign In to add comment