Este projeto é um transcritor e tradutor de áudio automatizado usando Whisper da OpenAI. O script pode baixar vídeos do YouTube, extrair o áudio, transcrever e traduzir o texto, salvando em arquivos de texto separados.
Daniel Dias
Site: https://linuxgo.com.br
Administrador da Comunidade Sandeco e apoiador do canal YouTube Sandeco
Matheus Bach
LeGen: matheusbach/legen
Ao executar o script principal main.py
, você verá o menu principal com a opção de fornecer um caminho para um arquivo .mp4
ou baixar um vídeo do YouTube. Escolha uma das opções:
- Fornecer um caminho para um arquivo
.mp4
- Baixar do YouTube
Após escolher a fonte do vídeo, o script solicitará que você selecione o idioma de entrada. Você verá uma lista de idiomas suportados. Digite o número correspondente ao idioma desejado.
O script solicitará que você selecione o modelo Whisper a ser usado. Escolha um dos modelos disponíveis digitando o número correspondente.
O script processará o áudio, gerará a transcrição e a tradução, e salvará os resultados em arquivos de texto separados no diretório textos_transcritos
.
texto-pro/
├── __init__.py
├── downloader.py
├── file_manager.py
├── main.py
├── transcriber.py
├── translator.py
├── utils.py
├── whisper_utils.py
├── venv/
│ └── ... (arquivos da virtual environment)
└── requirements.txt
downloader.py
: Contém a funçãodownload_video(url)
que baixa um vídeo do YouTube usandoyt_dlp
e salva no diretóriotemp
.file_manager.py
:save_transcription(base_filename, original_text, translated_text, target_language)
: Salva a transcrição e tradução em arquivos separados.handle_downloaded_video(mp4_file_path, keep_video, new_output_filename)
: Move ou remove o vídeo baixado com base na escolha do usuário.
main.py
: Script principal que gerencia o fluxo do programa.transcriber.py
: Contém a funçãoprocess_audio_file(mp3_file_path, model, input_language, output_filename)
que processa o áudio e gera a transcrição.translator.py
: Contém a funçãotranslate_text(original_text, detected_language)
que traduz o texto da transcrição para o idioma desejado.utils.py
:clear_screen()
: Limpa a tela.select_language()
: Permite a seleção do idioma de entrada.
whisper_utils.py
: Contém a funçãoload_model()
que carrega o modelo Whisper apropriado.
- Python 3.7 ou superior
- ffmpeg
- yt-dlp
- CUDA e cuDNN (para aceleração com GPU)
- Instalar dependências listadas no
requirements.txt
Verifique se sua GPU é compatível com CUDA no site da NVIDIA.
- Baixe o driver apropriado para sua GPU: Vá para o site de download de drivers da NVIDIA e baixe o driver adequado para sua placa gráfica.
- Instale o driver: Siga as instruções de instalação fornecidas pela NVIDIA.
- Baixe o CUDA Toolkit: Acesse o site de download do CUDA Toolkit e baixe a versão apropriada para seu sistema operacional.
- Instale o CUDA Toolkit:
-
No Linux, siga as instruções para instalar o CUDA Toolkit. Normalmente, você executará comandos como:
sudo dpkg -i cuda-repo-<distro>_<version>_amd64.deb sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/<distro>/x86_64/7fa2af80.pub sudo apt-get update sudo apt-get install cuda
-
No Windows, execute o instalador e siga as instruções na tela.
-
Após a instalação, adicione o CUDA ao seu PATH:
-
No Linux: Adicione as seguintes linhas ao seu
~/.bashrc
:export PATH=/usr/local/cuda/bin:$PATH export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
Em seguida, recarregue o
~/.bashrc
:source ~/.bashrc
-
No Windows: Adicione
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.4\bin
ao PATH nas variáveis de ambiente do sistema.
-
Baixe o cuDNN: Acesse o site de download do cuDNN e baixe a versão que corresponde à sua versão do CUDA.
-
Instale o cuDNN:
-
No Linux:
Extraia os arquivos do cuDNN e copie-os para os diretórios do CUDA:
tar -xzvf cudnn-<version>-linux-x64-v<version>.tgz sudo cp cuda/include/cudnn*.h /usr/local/cuda/include sudo cp -P cuda/lib64/libcudnn* /usr/local/cuda/lib64 sudo chmod a+r /usr/local/cuda/include/cudnn*.h /usr/local/cuda/lib64/libcudnn*
-
No Windows:
Extraia os arquivos do cuDNN e copie-os para os diretórios do CUDA. Normalmente, você colocará os arquivos no diretório
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.4
.
-
Para verificar se o CUDA e o cuDNN estão instalados corretamente, execute os seguintes comandos:
nvcc --version
Você deve ver a versão do CUDA Toolkit instalada.
Finalmente, instale o PyTorch com suporte a CUDA:
pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu11x
Para garantir que o PyTorch está configurado corretamente para usar a GPU, execute o seguinte código no Python:
import torch
print(torch.cuda.is_available())
Se a instalação estiver correta, isso deve retornar True
.
Clone o repositório:
git clone https://github.com/ecodelearn/textopro.git
cd textopro
Crie um ambiente virtual:
python -m venv venv
source venv/bin/activate # No Windows, use `venv\Scripts\activate`
Instale as dependências:
pip install -r requirements.txt
Instale o ffmpeg
e yt-dlp
, se ainda não estiverem instalados:
sudo apt-get install ffmpeg
pip install yt-dlp
Execute o script principal:
python main.py
Siga as instruções na tela:
- Escolha fornecer um caminho para um arquivo
.mp4
ou baixar do YouTube. - Se optar por baixar do YouTube, forneça o link do vídeo.
- Selecione o idioma de entrada.
- Selecione o modelo Whisper a ser usado.
- A transcrição e tradução serão salvas no diretório
textos_transcritos
.
This project is an automated audio transcriber and translator using OpenAI's Whisper. The script can download YouTube videos, extract the audio, transcribe, and translate the text, saving them into separate text files.
Daniel Dias
Website: https://linuxgo.com.br
Administrator of Sandeco Community and supporter of YouTube Sandeco
Matheus Bach
LeGen: matheusbach/legen
When running the main script main.py
, you'll see the main menu with options to provide a path to an .mp4
file or download a YouTube video. Choose one of the options:
- Provide a path to an
.mp4
file - Download from YouTube
After choosing the video source, the script will ask you to select the input language. You will see a list of supported languages. Type the number corresponding to the desired language.
The script will ask you to select the Whisper model to be used. Choose one of the available models by typing the corresponding number.
The script will process the audio, generate the transcription and translation, and save the results in separate text files in the textos_transcritos
directory.
texto-pro/
├── __init__.py
├── downloader.py
├── file_manager.py
├── main.py
├── transcriber.py
├── translator.py
├── utils.py
├── whisper_utils.py
├── venv/
│ └── ... (virtual environment files)
└── requirements.txt
downloader.py
: Contains the functiondownload_video(url)
that downloads a YouTube video usingyt_dlp
and saves it in thetemp
directory.file_manager.py
:save_transcription(base_filename, original_text, translated_text, target_language)
: Saves the transcription and translation into separate files.handle_downloaded_video(mp4_file_path, keep_video, new_output_filename)
: Moves or removes the downloaded video based on the user's choice.
main.py
: Main script managing the program flow.transcriber.py
: Contains the functionprocess_audio_file(mp3_file_path, model, input_language, output_filename)
that processes the audio and generates the transcription.translator.py
: Contains the functiontranslate_text(original_text, detected_language)
that translates the transcription text to the desired language.utils.py
:clear_screen()
: Clears the screen.select_language()
: Allows the selection of the input language.
whisper_utils.py
: Contains the functionload_model()
that loads the appropriate Whisper model.
- Python 3.7 or higher
- ffmpeg
- yt-dlp
- CUDA and cuDNN (for GPU acceleration)
- Install dependencies listed in
requirements.txt
Ensure your GPU is CUDA-compatible on NVIDIA's website.
- Download the appropriate driver for your GPU: Go to the NVIDIA driver download page and download the correct driver for your GPU.
- Install the driver: Follow NVIDIA's installation instructions.
- Download CUDA Toolkit: Visit the CUDA Toolkit download page and download the correct version for your operating system.
- Install CUDA Toolkit:
-
On Linux, follow the instructions to install the CUDA Toolkit. Typically, you will run commands like:
sudo dpkg -i cuda-repo-<distro>_<version>_amd64.deb sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/<distro>/x86_64/7fa2af80.pub sudo apt-get update sudo apt-get install cuda
-
On Windows, run the installer and follow the on-screen instructions.
-
After installation, add CUDA to your PATH:
-
On Linux: Add the following lines to your
~/.bashrc
:export PATH=/usr/local/cuda/bin:$PATH export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
Then reload the
~/.bashrc
:source ~/.bashrc
-
On Windows: Add
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.4\bin
to the system environment variables PATH.
-
Download cuDNN: Visit the cuDNN download page and download the version that matches your CUDA version.
-
Install cuDNN:
-
On Linux:
Extract the cuDNN files and copy them to the CUDA directories:
tar -xzvf cudnn-<version>-linux-x64-v<version>.tgz sudo cp cuda/include/cudnn*.h /usr/local/cuda/include sudo cp -P cuda/lib64/libcudnn* /usr/local/cuda/lib64 sudo chmod a+r /usr/local/cuda/include/cudnn*.h /usr/local/cuda/lib64/libcudnn*
-
On Windows:
Extract the cuDNN files and copy them to the CUDA directories. Typically, you will place the files in
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.4
.
-
To verify that CUDA and cuDNN are correctly installed, run the following commands:
nvcc --version
You should see the installed version of the CUDA Toolkit.
Finally, install PyTorch with CUDA support:
pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu11x
To ensure PyTorch is properly set up to use the GPU, run the following code in Python:
import torch
print(torch.cuda.is_available())
If the installation is correct, this should return True
.
Clone the repository:
git clone https://github.com/ecodelearn/textopro.git
cd textopro
Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows, use `venv\Scripts\activate`
Install the dependencies:
pip install -r requirements.txt
Install ffmpeg
and yt-dlp
if not already installed:
sudo apt-get install ffmpeg
pip install yt-dlp
Run the main script:
python main.py
Follow the on-screen instructions:
- Choose to provide a path to an
.mp4
file or download from YouTube. - If downloading from YouTube, provide the video link.
- Select the input language.
- Select the Whisper model to be used.
- The transcription and translation will be saved in the
textos_transcritos
directory.
This project is licensed under the terms of the GNU GPLv3.