alphacep / vosk-api

Offline speech recognition API for Android, iOS, Raspberry Pi and servers with Python, Java, C# and Node
Apache License 2.0
7.84k stars 1.09k forks source link

Amount of words per line in a SubRip file #1370

Closed cslop3r closed 1 year ago

cslop3r commented 1 year ago

Hello, is there a way to add only one word per line? Here is my code, it's almost the same than in python/example/test_srt.py with open("subs.srt", "w", encoding='utf-8') as f: print("→ Fabrication des sous-titres") SAMPLE_RATE = 16000 SetLogLevel(-1) model = Model(model_name="vosk-model-fr-0.22") rec = KaldiRecognizer(model, SAMPLE_RATE) rec.SetWords(True) with subprocess.Popen(["ffmpeg", "-loglevel", "quiet", "-i", "audio.wav", "-ar", str(SAMPLE_RATE) , "-ac", "1", "-f", "s16le", "-"], stdout=subprocess.PIPE).stdout as stream: f.write(rec.SrtResult(stream))

cslop3r commented 1 year ago

up? 🙏

nshmyrev commented 1 year ago

You don't have to use srt then, just try to load json output from the recognizer, it has word timestamps

cslop3r commented 1 year ago

Thanks for your answer! Would you have an example code to load json output? I tried that but it doesn't work: result = json.loads(rec.Result()) with open("output.json", "w") as output_file: json.dump(result, output_file)

nshmyrev commented 1 year ago

what doesn't work for you exactly?

cslop3r commented 1 year ago

what doesn't work for you exactly?

The only content of the json file is : {"text": ""}

cslop3r commented 1 year ago

what doesn't work for you exactly?

The only content of the json file is : {"text": ""}

up? 🙏