-
-
Save vkostyanetsky/4f4760097f1b417cc85d71d11662a642 to your computer and use it in GitHub Desktop.
Convert Video To Text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @echo off | |
| setlocal EnableExtensions | |
| set "WHISPER_DIR=D:\Me\Utils\Whisper" | |
| set "PYTHON_VENV=%WHISPER_DIR%\.venv\Scripts\python.exe" | |
| set "AUDIO=%~dp0audio.wav" | |
| echo. | |
| echo [1/5] Looking for video... | |
| set "VIDEO=" | |
| for %%F in ("%~dp0*.mkv") do ( | |
| set "VIDEO=%%~fF" | |
| goto :got_video | |
| ) | |
| :got_video | |
| if not defined VIDEO ( | |
| echo [ERR] No .mkv found in "%~dp0" | |
| exit /b 1 | |
| ) | |
| echo Video: "%VIDEO%" | |
| where /q ffmpeg.exe | |
| if errorlevel 1 ( | |
| echo [ERR] ffmpeg not found | |
| exit /b 1 | |
| ) | |
| if not exist "%PYTHON_VENV%" ( | |
| echo [ERR] Python venv not found: "%PYTHON_VENV%" | |
| exit /b 1 | |
| ) | |
| echo. | |
| echo [2/5] Checking venv... | |
| "%PYTHON_VENV%" -c "import sys; print('executable:', sys.executable); print('prefix:', sys.prefix); print('base_prefix:', sys.base_prefix)" | |
| echo. | |
| echo [3/5] Checking cuda... | |
| "%PYTHON_VENV%" -c "import torch; print('torch', torch.__version__); print('cuda', torch.version.cuda); print('is_available', torch.cuda.is_available()); print(torch.cuda.get_device_name(0) if torch.cuda.is_available() else 'no gpu')" | |
| echo. | |
| echo [4/5] Extracting audio... | |
| ffmpeg.exe -hwaccel nvdec -y -i "%VIDEO%" -vn -ac 1 -ar 16000 -af loudnorm -c:a pcm_s16le "%AUDIO%" | |
| if errorlevel 1 ( | |
| echo [ERR] ffmpeg failed | |
| exit /b 1 | |
| ) | |
| echo. | |
| echo [5/5] Transcribing audio... | |
| pushd "%WHISPER_DIR%" || ( | |
| echo [ERR] Can't jump to Whisper dir: "%WHISPER_DIR%" | |
| exit /b 1 | |
| ) | |
| "%PYTHON_VENV%" -m whisper "%AUDIO%" --model medium --model_dir "%WHISPER_DIR%\models" --language Russian --device cuda --output_format txt --output_dir "%~dp0." | |
| set "WERR=%errorlevel%" | |
| popd | |
| if not "%WERR%"=="0" ( | |
| echo [ERR] Whisper failed | |
| exit /b %WERR% | |
| ) | |
| echo. | |
| echo [OK] Done! | |
| exit /b 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment