Google Colab is a free cloud-based programming environment. You can think of it as a computer in the cloud where you can run code, process data, and even perform complex AI calculations, such as quickly and accurately converting your audio and video files into subtitles using large models.
This article will guide you step-by-step on how to use pyVideoTrans on Colab to transcribe audio and video into subtitles. Even if you don't have any programming experience, it's okay. We'll provide a pre-configured Colab notebook that you can use by simply clicking a few buttons.
Preparation: Magic Internet and Google Account
Before you begin, you'll need two things:
- Magic Internet: Due to certain reasons, Google services are not directly accessible in some regions. You'll need to use special methods to access Google websites.
- Google Account: You need a Google account to use Colab. Registration is completely free. With a Google account, you can log in to Colab and use its services.
Confirm you can open Google: https://google.com
Open the Colab Notebook
After ensuring you can access Google websites and are logged in to your Google account, click the following link to open the Colab notebook we've prepared for you:
https://colab.research.google.com/drive/1kPTeAMz3LnWRnGmabcz4AWW42hiehmfm?usp=sharing
You will see an interface similar to the image below. Since this is a shared notebook, you need to copy it to your own Google Drive before you can modify and run it. Click "Copy to Drive" in the upper left corner, and Colab will automatically create a copy for you and open it.
The following image shows the created page:
Connect to GPU/TPU
Colab uses CPU to run code by default. To speed up the transcription, we need to use a GPU or TPU.
Click "Runtime" -> "Change runtime type" in the menu bar, and then select "GPU" or "TPU" in the "Hardware accelerator" drop-down menu. Click "Save".
Once saved, you are done. If a dialog box pops up, choose "Allow," "Agree," etc.
The usage is very simple, divided into three steps.
1. Pull the Source Code and Install the Environment
Find the first code block (the gray area with the play button) and click the play button to execute the code. This code will automatically download and install pyvideotrans and other software it needs.
Wait for the code to finish executing, and you will see the play button turn into a checkmark. Red error messages may appear during the process, which can be ignored.
2. Check if GPU/TPU is Available
Run the second code block to confirm whether the GPU/TPU is connected successfully. If the output shows support for CUDA, it means the connection is successful. If it is not connected successfully, please go back and double-check whether you have connected to GPU/TPU.
3. Upload Audio and Video and Perform Transcription
- Upload File: Click the file icon on the left side of the Colab interface to open the file browser.
You can directly drag and drop your audio and video files from your computer to the blank area of the file browser to upload them.
Copy File Path: After uploading, right-click on the file name and select "Copy path" to get the full path of the file (e.g.,
/content/your_file_name.mp4
).Execute command
Take the following command as an example:
!python3 cli.py --model large-v2 --language zh --file "/content/1.mp4"
!python3 cli.py
This is a fixed starting command, including the exclamation mark.After
cli.py
, you can add control parameters, such as which model to use, what the audio and video language is, whether to use GPU or CPU, and where to find the audio and video files to be transcribed. Among them, only theaudio and video file address
is required. Others can be omitted and use the default values.
Suppose your video name is 1.mp4
. After uploading, copy the path, and when pasting the path, be sure to enclose it in English double quotes to prevent errors caused by spaces in the name.
!python3 cli.py --file "Paste the copied path here"
After pasting and replacing it, it becomes: !python3 cli.py --file "/content/1.mp4"
Then click the execute button and wait for it to finish. The required model will be automatically loaded, and the download speed is very fast.
The default model is
large-v2
. What if you want to change it to the large-v3 model? Execute the following command:
!python3 cli.py --model large-v3 --file "Paste the copied path"
What if you also want to set the language to Chinese?
!python3 cli.py --model large-v3 --language zh --file "Paste the copied path"
Where to Find the Transcription Results
After the execution starts, you will find an output
folder in the folder list on the left. All transcription results are located here, named after the original audio and video names.
Click on the output
name to view all the files inside. Right-click on a file and click "Download" to download it to your local computer.
Precautions
- Magic Internet
- The uploaded files and generated SRT files are only temporarily stored in Colab. When the connection is disconnected or the Colab free time limit is reached, the files will be automatically deleted, including all pulled source code and all installed dependencies. So please download the generated results in time.
- When you open Colab again, or when the connection is disconnected and reconnected, you need to start from the first step again.
4. If you close the browser, where can you find it next time?
Open this address: https://colab.research.google.com/
Click on the name used last time.
- As shown in the figure above, if the name is difficult to remember, how to modify it?