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.57k stars 1.06k forks source link

Automatic .srt file #1347

Closed cslop3r closed 1 year ago

cslop3r commented 1 year ago

Hello, is it possible in Python to use vosk-api to make automatic subtitles (.srt file) using a audio (.wav) file like in Subtitle Edit app? If yes, how? Thanks for your answer

nshmyrev commented 1 year ago

Sure, see example here:

https://github.com/alphacep/vosk-api/blob/master/python/example/test_srt.py

cslop3r commented 1 year ago

Sure, see example here:

https://github.com/alphacep/vosk-api/blob/master/python/example/test_srt.py

Thanks for your answer! I saw this example, however I don't exactly get it.

Where do I put the name of my audio file in order that it creates subtitles?

Why do I get list index out of range error with sys.argv[1],?

Also, why does Model(lang="fr") uses small model instead of the big one?

Sorry for all these questions, hoping you can help me

nshmyrev commented 1 year ago

Where do I put the name of my audio file in order that it creates subtitles?

You can use the name of the file instead of sys.argv[1]

Why do I get list index out of range error with sys.argv[1],?

Because you do not provide command line argument

Also, why does Model(lang="fr") uses small model instead of the big one?

You have to specify model name instead Model(model_name="vosk-model-fr-0.22")

cslop3r commented 1 year ago

Thanks a lot it works! Last question, how to save as .srt file instead of print it?

nshmyrev commented 1 year ago

Something like

with open("file.srt", "w") as fh:
     fh.write(rec.SrtResult(stream))
cslop3r commented 1 year ago

Thanks!!! Is there an option to save with an encoding utf-8 without BOM?

nshmyrev commented 1 year ago

I suppose

with open("file.srt", "w", encoding='utf-8') as fh:
     fh.write(rec.SrtResult(stream))
cslop3r commented 1 year ago

I suppose

with open("file.srt", "w", encoding='utf-8') as fh:
     fh.write(rec.SrtResult(stream))

Ah yes I'm dumb. Thank you for your help, have a nice evening!

nshmyrev commented 1 year ago

Ok, let us know how it goes