This repository contains a Python script that transcribes and translates live audio from a Twitch stream. The script uses OpenAI's Whisper model for transcription and Hugging Face's MarianMT model for translation. It supports dynamic language translation for most languages. It has been tested on 20 so far but should work on hundreds.
In short, if you speak X and want to understand a stream where the streamer speaks Y, this will do that.
If you like this repo, hit the star, help others find it!
Clone the Repository
git clone https://github.com/gorgarp/TwitchTranslate.git
cd TwitchTranslate
Install FFmpeg
brew install ffmpeg
sudo apt-get install ffmpeg
Using a virtual environment is one approach to running the script. This method keeps your dependencies isolated from your system Python environment.
Create a Virtual Environment
python -m venv myenv
Activate the Virtual Environment
myenv\Scripts\activate
source myenv/bin/activate
Install the Required Python Packages
pip install -r requirements.txt
Set Up Twitch API Token
CLIENT_ID
and CLIENT_SECRET
.YOUR_TWITCH_CLIENT_ID
and YOUR_TWITCH_CLIENT_SECRET
in the script with your actual Twitch API credentials.Configure the Twitch Channel
YOUR_TWITCH_CHANNEL_NAME
with the name of the Twitch channel you want to transcribe and translate.python transcribe_translate.py <source_lang> <target_lang>
python transcribe_translate.py es en # Translates Spanish to English
python transcribe_translate.py pl en # Translates Polish to English
Confirmed Languages
"en", "fr", "de", "es", "it", "nl", "sv", "pl", "pt", "ru", "zh", "ja", "ko",
"ar", "tr", "da", "fi", "no", "cs", "el"
Note: These have been tested, but it should work on any language pair found on Helsinki-NLP on Hugging Face.
Add Language Pair to Exceptions List
Helsinki-NLP/opus-mt-{source_lang}-{target_lang}
, you need to add an exception.exceptions
dictionary in the script with the new language pair and the corresponding model name. (See Exceptions Handling)Transcription
Translation
System Messages and Error Handling
The script can run on either CUDA (GPU) or CPU. Using CUDA significantly improves the performance and speed of both transcription and translation.
Checking CUDA Availability
device = "cuda" if torch.cuda.is_available() else "cpu"
logging.info(f"Using device: {device}")
Installing CUDA (if needed)
Windows:
$env:Path += ";C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.5\bin"
nvcc --version
Note: The above commands reference CUDA version 12.5. If you install a different version, adjust the paths accordingly.
macOS: CUDA is not supported on macOS.
Linux:
export PATH=/usr/local/cuda-12.5/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-12.5/lib64\
${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
nvcc --version
Note: The above commands reference CUDA version 12.5. If you install a different version, adjust the paths accordingly.
Installing PyTorch with CUDA Support
pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu117
Note: The above command installs PyTorch with CUDA 11.7 support. Ensure the versions are compatible with your CUDA installation.
Helsinki-NLP/opus-mt-{source_lang}-{target_lang}
for loading models.pt-en
), the script uses Helsinki-NLP/opus-mt-mul-en
as the model name.Note: Helsinki-NLP on Hugging Face is where you can find language combinations.
git checkout -b feature-branch
git commit -m "Add some feature"
git push origin feature-branch
For any questions or issues, please open an issue in the GitHub repository.
This project is licensed under the MIT License.