Google Colab is a free cloud-based programming environment. You can think of it as a computer in the cloud that 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 to transcribe audio and video into subtitles on Colab. Even if you don't have any programming experience, it doesn't matter. We will provide a pre-configured Colab notebook, and you only need to click a few buttons to complete the process.
Preparation: Internet Access and Google Account
Before you begin, you'll need two things:
- Internet Access: Due to some reasons, direct access to Google services is not possible in some regions. You will need to use special methods to access Google websites.
- Google Account: You need a Google account to use Colab, and registration is completely free. With a Google account, you can log in to Colab and use its services.
Make sure you can open Google: https://google.com
Open the Colab Notebook
After ensuring you can access the Google website and log in to your Google account, click the following link to open the Colab notebook we have prepared for you:
https://colab.research.google.com/drive/1kPTeAMz3LnWRnGmabcz4AWW42hiehmfm?usp=sharing
You will see an interface similar to the one 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.
As shown below, this is 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".
After saving, you are all set. If a dialog box pops up, select "Allow" or "Agree" in all cases.
It is very simple to use, with a total of three steps.
1. Pull the Source Code and Install the Environment
Find the first code block (the gray area with a play button) and click the play button to execute the code. This code will automatically download and install pyvideotrans and the 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, but you can ignore them.
2. Check if GPU/TPU is Available
Run the second code block to confirm whether the GPU/TPU is successfully connected. If the output shows that CUDA is supported, it means the connection is successful. If it is not connected successfully, please go back and double-check whether you have connected to the GPU/TPU.
3. Upload Audio/Video and Execute Transcription
- Upload Files: Click the file icon on the left side of the Colab interface to open the file browser.
Drag and drop your audio and video files directly from your computer to the blank space in the file browser to upload them.
- Copy File Path: After uploading, right-click on the file name and select "Copy path" to get the complete file path (for example:
/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, which is indispensable.
cli.py
can be followed by control parameters, such as which model to use, the audio/video language, whether to use GPU or CPU, and where to find the audio/video files to transcribe. Among them, only theaudio/video file address
is required, and the others can be omitted and use the default values.
If your video name is 1.mp4
, copy the path after uploading, and be sure to enclose the path in English double quotes when pasting to prevent errors caused by spaces in the name.
!python3 cli.py --file "Paste the copied path here"
After pasting and replacing, 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
. If you want to change it to thelarge-v3
model, execute the following command:
!python3 cli.py --model large-v3 --file "Paste the copied path"
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 appearing 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 within it. Right-click on a file and click "Download" to download it to your local computer.
Precautions
- Internet access is essential.
- 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 the source code pulled and all the dependencies installed. Therefore, 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 you used last time.
- As shown in the figure above, if the name is difficult to remember, how do you change it?