Transcribe videos with google colab and openai whisper
Google colab provides powerful GPUs with 12G of VRAM even at free tier. I foud this very useful to first generate srt files of chinese youtube videos and then translate the chinese srt files into english srt files.
Sample ffmpeg command to extract audio from video
First visit https://colab.research.google.com/
Set the runtime type
Select python3 as interpreter and t4 gpu as hardware accelator
Each code bock below is inserted by pressing the +Code
button in the UI first
and then entering the text. Lines that beings with !
is run in the os shell
environment, while the rest are run in the selected interpreter (here python3).
After typing in each code blocks, press the run button:
The codeblocks (run in sequence)
- Click on Choose Files, navigate to and select file.
- This is done to print the name of the uploaded file so that we can copy it easily. We use this later.
!whisper '狠甩F-15一條街!傳中國無偵-7開掛升空嚇壞日本寶寶 美軍也呆了!【#環球大戰線】20250605-P2 葉思敏 蔡正元 鄭繼文 聶建中 [aK6jyS2GkhU].mp3'
\ --output_format srt --language zh --model turbo # (1)
Note
- Replace "狠甩F-15一條街!傳中國無偵-7開掛升空嚇壞日本寶寶 美軍也呆了!【#環球大戰線】20250605-P2 葉思敏 蔡正元 鄭繼文 聶建中 [aK6jyS2GkhU].mp3" with the name of the file you uploaded
- Replace zh with the spoken language in the video
files.download("狠甩F-15一條街!傳中國無偵-7開掛升空嚇壞日本寶寶 美軍也呆了!【#環球大戰線】20250605-P2 葉思敏 蔡正元 鄭繼文 聶建中 [aK6jyS2GkhU].srt")
Note
- The generated srt file has the same name but different
srt
as extension.
Translate with google translate
At https://translate.google.com, in Documents
tab you see that google ony supports .docx, .pdf, .pptx, .xlsx.
To work around this i had libreoffice open this file and save it as .docx
. Surprisingly it took less than a second for google
to translate this. I downloaded the file and changed the extension to srt.