Last active
May 13, 2024 07:48
-
-
Save ThioJoe/e836e651c7d51697ce4709587891b346 to your computer and use it in GitHub Desktop.
WhisperCPP Batch File Script
This file contains 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
:: ---- Lines beginning with :: are comments ---- | |
:: This script is meant to make it easy to transcribe a video file using WhisperCPP. | |
:: You can simply drag a video file into the cmd window, then it will use ffmpeg to extract the audio, then transcribe using WhisperCPP and output to a text file. | |
:: | |
@echo off | |
set /p videopath="Enter the full path to the video file to transcribe: " | |
:: Remove quotes from the input path | |
set videopath=%videopath:"=% | |
:: Extracting the base filename without the extension | |
for %%A in ("%videopath%") do set "basename=%%~nA" | |
:: Get the directory of the batch file | |
set "scriptdir=%~dp0" | |
:: Ensure the output directory exists | |
if not exist "%scriptdir%output\" mkdir "%scriptdir%output" | |
:: Extracting audio from the video file - You probably shouldn't change this. It extracts the audio with settings that Whisper uses natively | |
:: Just make sure ffmpeg is either in your PATH environment variable, or within the same folder as the script | |
ffmpeg -i "%videopath%" -vn -acodec pcm_s16le -ar 16000 -ac 2 temp.wav | |
:: Running Whisper CPP main.exe with the parameters, specifying full path for output | |
:: Here you can change around the parameters that get used | |
main.exe -t 16 -p 1 -otxt -of "%scriptdir%output\%basename%" -l en -bs 5 -bo 5 -m ggml-large-v2.bin -f temp.wav --prompt "Hello." | |
:: Deleting the temporary wave file | |
del temp.wav | |
:: Use PowerShell to remove newlines | |
set "textfile=%scriptdir%output\%basename%.txt" | |
set "tempfile=%scriptdir%output\temp.txt" | |
powershell -command "(Get-Content '%textfile%') -join ' ' | Set-Content '%tempfile%'" | |
move /Y "%tempfile%" "%textfile%" | |
:: Wait for user input before closing and open output directory | |
set /p EXIT_INPUT="Done! Close this window, or press Enter to open the Output folder and exit..." | |
start "" "explorer.exe" "%scriptdir%output" | |
exit /b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment