chenxwh / cog-whisper

MIT License
81 stars 28 forks source link

Add option to SRT translate output - Fix inside #15

Open GodlikeRU opened 1 year ago

GodlikeRU commented 1 year ago

Translation works only for plain text for now. It's useless if you would like to translate YouTube video to upload subtitles for English for example. This modified code will make sure translation output is also formatted to SRT.

Start on line 137, predict.py:

if translate: translationResult = model.transcribe( str(audio), task="translate", temperature=temperature, **args )

MODIFIED to translate to SRT

        translation = write_srt(translationResult["segments"])
    return ModelOutput(
        segments=result["segments"],
        detected_language=LANGUAGES[result["language"]],
        transcription=transcription,
        translation=translation if translate else None,
    )

I tested it on another model, works great.