教你3分鐘做出一個AI影片轉字幕程式!無需安裝軟硬體,google雲端輕鬆搞定

Поделиться
HTML-код
  • Опубликовано: 31 дек 2024

Комментарии • 1

  • @pitv1
    @pitv1  3 месяца назад

    Colab 範例程式:
    colab.research.google.com/drive/1daS9jIBivCuK7o_ikaau3CMQK2TwSiWv?usp=drive_link
    前置作業:
    !pip install faster_whisper nvidia-cublas-cu12
    參考程式碼:
    from faster_whisper import WhisperModel
    from google.colab import drive
    drive.mount('google硬碟')
    trans = ""
    model = WhisperModel("large-v3", device="cuda", compute_type="float16")
    # 改成你的檔案名稱
    filename = "google硬碟/MyDrive/test.mp3"
    segs, info = model.transcribe(filename, beam_size=5, initial_prompt="臺灣的繁體中文")
    for i, seg in enumerate(segs, 1):
    startHH, startRR = divmod(seg.start, 3600)
    startMM, startSR = divmod(startRR*1000, 60000)
    startSI, startSF = divmod(startSR, 1000)
    endHH, endRR = divmod(seg.end, 3600)
    endMM, endSR = divmod(endRR*1000, 60000)
    endSI, endSF = divmod(endSR, 1000)
    trans += "%d
    %02d:%02d:%02d,%03d --> %02d:%02d:%02d,%03d
    %s

    " % (
    i,
    startHH, startMM, startSI, startSF,
    endHH, endMM, endSI, endSF,
    seg.text
    )
    print (trans)
    srtfile=open(filename+".txt", "w")
    srtfile.write(trans)
    srtfile.close()