summaryrefslogtreecommitdiffstats
path: root/roles/caption
diff options
context:
space:
mode:
authorSacha Chua <sacha@sachachua.com>2022-10-23 08:32:04 -0400
committerSacha Chua <sacha@sachachua.com>2022-10-23 08:32:04 -0400
commit8929a1ce7bd8afb9da6a34443b71c2816c40c680 (patch)
tree3ad395fc14ab4dd1b40986c46d7f5bf294ce7e99 /roles/caption
parentf636dd1ef7593a60aa8c287fb0346045a321cbc5 (diff)
downloademacsconf-ansible-8929a1ce7bd8afb9da6a34443b71c2816c40c680.tar.xz
emacsconf-ansible-8929a1ce7bd8afb9da6a34443b71c2816c40c680.zip
Captioning tools
Diffstat (limited to '')
-rw-r--r--roles/caption/tasks/main.yml6
-rwxr-xr-xroles/caption/templates/caption.sh18
2 files changed, 24 insertions, 0 deletions
diff --git a/roles/caption/tasks/main.yml b/roles/caption/tasks/main.yml
index 7b6534a..7bf45d0 100644
--- a/roles/caption/tasks/main.yml
+++ b/roles/caption/tasks/main.yml
@@ -6,3 +6,9 @@
- name: Install whisper
ansible.builtin.pip:
name: git+https://github.com/openai/whisper.git
+- name: Copy the shell script
+ tags: caption-sh
+ template:
+ src: caption.sh
+ dest: current
+ mode: 0755
diff --git a/roles/caption/templates/caption.sh b/roles/caption/templates/caption.sh
new file mode 100755
index 0000000..9600a3c
--- /dev/null
+++ b/roles/caption/templates/caption.sh
@@ -0,0 +1,18 @@
+#!/bin/bash
+# {{ ansible_managed }}
+FILE="$1"
+MODEL="${2:small}"
+AUDIO=$(basename "$FILE" | sed s/\\.[a-z][a-z][a-z][a-z]?$//).ogg
+if [[ ! -f $AUDIO ]]; then
+ if [[ "$FILE" == *webm ]]; then
+ ffmpeg -y -i "$FILE" -acodec copy -vn $AUDIO
+ else
+ ffmpeg -y -i "$FILE" -acodec libvorbis -vn $AUDIO
+ fi
+fi
+date > $AUDIO-$MODEL.log
+time whisper $AUDIO --model $MODEL --threads 12 >> $AUDIO-$MODEL.log
+for EXT in vtt txt srt; do
+ mv $AUDIO.$EXT $(basename -s .webm.$EXT $AUDIO.$EXT)
+done
+date >> $AUDIO-$MODEL.log