zh-plus / openlrc

Transcribe and translate voice into LRC file using Whisper and LLMs (GPT, Claude, et,al). 使用whisper和LLM(GPT,Claude等)来转录、翻译你的音频为字幕文件。
https://zh-plus.github.io/openlrc/
MIT License
459 stars 33 forks source link

如何指定 `srt` 格式输出? #37

Closed piwawa closed 5 months ago

piwawa commented 6 months ago

使用以下代码:

lrcer.run("/home/bingo06/AIGC/auto_ai_subtitle/video/output.m4a", src_lang='yue', target_lang='zh-cn', skip_trans=True)

生成结果为:

 [2024-05-18 01:19:44] INFO     [MainThread] Default context config not found: Context(background=, audio_type=Anime, description_map={}), using default context.
 [2024-05-18 01:19:44] INFO     [MainThread] Preprocessed audio already exists in /home/bingo06/AIGC/auto_ai_subtitle/video/preprocessed/output_preprocessed.wav
 [2024-05-18 01:19:44] INFO     [MainThread] Loudness normalizing...
 [2024-05-18 01:19:44] INFO     [MainThread] Working on 1 audio files: [PosixPath('/home/bingo06/AIGC/auto_ai_subtitle/video/preprocessed/output_preprocessed.wav')]
 [2024-05-18 01:19:44] INFO     [MainThread] Start Transcription (Producer) and Translation (Consumer) process
 [2024-05-18 01:19:44] INFO     [Producer_0] Found transcribed json file: /home/bingo06/AIGC/auto_ai_subtitle/video/preprocessed/output_preprocessed_transcribed.json
 [2024-05-18 01:19:44] INFO     [Producer_0] Transcription producer finished.
 [2024-05-18 01:19:44] INFO     [ThreadPoolExecutor-1_0] Got transcription: /home/bingo06/AIGC/auto_ai_subtitle/video/preprocessed/output_preprocessed_transcribed.json
 [2024-05-18 01:19:44] INFO     [ThreadPoolExecutor-1_0] Optimized json file saved to /home/bingo06/AIGC/auto_ai_subtitle/video/preprocessed/output_preprocessed_transcribed_optimized.json
 [2024-05-18 01:19:44] INFO     [ThreadPoolExecutor-1_0] File saved to /home/bingo06/AIGC/auto_ai_subtitle/video/preprocessed/output_preprocessed.lrc
 [2024-05-18 01:19:44] INFO     [Consumer_0] Transcription consumer finished.
 [2024-05-18 01:19:44] INFO     [MainThread] Transcription (Producer) and Translation (Consumer) process Elapsed: 0.03s
 [2024-05-18 01:19:44] INFO     [MainThread] Totally used API fee: 0.0000 USD

希望可以指定用 srt 或是 lrc 输出。

zh-plus commented 6 months ago
from openlrc.subtitle import Subtitle

if __name__ == '__main__':
    lrcer.run("/home/bingo06/AIGC/auto_ai_subtitle/video/output.m4a", src_lang='yue', target_lang='zh-cn', skip_trans=True)
    subtitle = Subtitle.from_file('/home/bingo06/AIGC/auto_ai_subtitle/video/output.lrc')
    subtitle.to_srt()

You can convert the format yourself. Note that if the audio length is more than one hour, lrcer.run will automatically output in .srt format.