Last active
July 1, 2023 11:28
-
-
Save jnorthrup/75671a1087fa0a454da2f7394f1afb7d to your computer and use it in GitHub Desktop.
record a pulsaudio telegram chat and whisper transcription based on recent gentoo build
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
#!/bin/bash | |
# Define the Whisper function | |
whisp() { | |
source ~/extras/venv/bin/activate # ymmv, this is my "userspace" requirement | |
whisper --model medium.en --output_format=all $@ #pip3 install openai-whisper to get this | |
} | |
# Get the sink input index for 'telegram-desktop' | |
sink_input_index=$(pactl list short | grep 'telegram-desktop' | cut -f1|head -n1 ) | |
full_volname=$( date -Is|sed -e 's,\W,_,g').wav | |
parecord -d $sink_input_index >$full_volname & | |
echo writing index $sink_input_index to ${full_volname} | |
# Get the process ID of the parecord command | |
recording_pid=$! | |
# Prompt the user to stop recording | |
echo "Press enter key to stop recording..." | |
read -n1 -r -p "" key | |
# Send the SIGINT signal to stop the recording | |
kill -INT $recording_pid | |
# Wait for a moment for file sync | |
sleep 1 | |
# Error handling for Whisper | |
whisp $full_volname || { echo "Whisper failed."; exit 1; } | |
# Rename the file | |
new_filename="${full_volname/%.wav/.mkv}" # Change the extension to .mkv | |
subtitles="${full_volname/%.wav/.vtt}" # Change the extension to .mkv | |
#add -i mylogo.png below to make a video | |
set -x | |
if ffmpeg -i $full_volname -c:a libopus -i $subtitles $new_filename; then | |
echo "Conversion and muxing successful. New file: $new_filename, cleaning up" | |
rm $full_volname | |
else | |
echo "Conversion or muxing failed." | |
exit 1 | |
fi | |
set +x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment