aboutsummaryrefslogtreecommitdiffstats
path: root/subtitle-podcast/subtitle-podcast.ps1
diff options
context:
space:
mode:
authormjfernez <mjf@mjfer.net>2026-01-17 01:31:49 -0500
committermjfernez <mjf@mjfer.net>2026-01-17 01:31:49 -0500
commited545019a981790962caf8e83a8821a4f1a17667 (patch)
tree5f296b8b0583d3e2be2630ae1b9651f6840fe059 /subtitle-podcast/subtitle-podcast.ps1
parent6b85765bffdb27b1b2c5800a58159e6a179b00fb (diff)
downloadscripts-n-tools-ed545019a981790962caf8e83a8821a4f1a17667.tar.gz
Add subtitle-podcast.ps1 script
Diffstat (limited to 'subtitle-podcast/subtitle-podcast.ps1')
-rw-r--r--subtitle-podcast/subtitle-podcast.ps167
1 files changed, 67 insertions, 0 deletions
diff --git a/subtitle-podcast/subtitle-podcast.ps1 b/subtitle-podcast/subtitle-podcast.ps1
new file mode 100644
index 0000000..d50931c
--- /dev/null
+++ b/subtitle-podcast/subtitle-podcast.ps1
@@ -0,0 +1,67 @@
+<#
+Usage:
+ .\subtitle-podcast.ps1 episode01.mp3
+
+Place cover files in the same directory as your mp3, with a name like "episode01.jpg" (PNG is also OK)
+
+If a cover is not supplied, a black background will be made instead
+
+Requirements:
+ - Python in PATH
+ - ffmpeg in PATH
+ whispeX installed via pip
+#>
+
+param (
+ [Parameter(Mandatory = $true)]
+ [string]$InputAudio
+)
+
+# https://github.com/m-bain/whisperX/issues/1304#issuecomment-3599061751
+$env:TORCH_FORCE_NO_WEIGHTS_ONLY_LOAD = "true"
+
+$Title = [System.IO.Path]::GetFileNameWithoutExtension($InputAudio)
+
+Write-Host "Processing: $InputAudio"
+Write-Host "Base title: $Title"
+
+# -----------------------------
+# Run WhisperX
+# ----------------------------
+# https://github.com/m-bain/whisperX/issues/878
+whisperx `
+ --compute_type float32 `
+ --model large-v2 `
+ --align_model WAV2VEC2_ASR_LARGE_LV60K_960H `
+ --output_format srt `
+ --batch_size 4 `
+ --highlight_words True `
+ $InputAudio
+
+
+# -----------------------------
+# Create subtitled video
+# -----------------------------
+$OutputVideo = "$Title.mkv"
+
+$Image = @()
+if (Test-Path "$Title.jpg") {
+ $Image += @("-loop", "1", "-i", "$Title.jpg")
+} elseif (Test-Path "$Title.png") {
+ $Image += @("-loop", "1", "-i", "$Title.png")
+} else{
+ Write-Warning "No image with '$Title' found, making blank background"
+ $Image += @("-f", "lavfi", "-i", "color=c=black:s=1280x720")
+}
+
+
+ffmpeg `
+ @Image `
+ -i $InputAudio `
+ -vf "subtitles=${Title}.srt:force_style='FontSize=28,Alignment=2'" `
+ -c:a copy `
+ -shortest `
+ $OutputVideo
+
+Write-Host "Done!"
+Write-Host "Output: $OutputVideo"