WIP: Create initial storytime script

This commit is contained in:
Clinton Judy 2024-04-12 00:49:01 -04:00
parent 3ac8ba51ab
commit 003be90eaa

View file

@ -1,53 +1,44 @@
#!/bin/bash
#!/usr/bin/env bash
# Abort if any command fails.
set -e
# Check for presence of a command.
# $1 is name of dependency
# $2 is command that gets run to check for it
# eg. check "disroot.org reachable?" "ping disroot.org"
check() {
echo -n "Checking for $1... "
if eval $2 &> /dev/null ; then
echo ✔︎
false
else
echo
storytime_ready=false
true
fi
usage() {
echo "Storytime - Convert your RSS feeds into personalized podcasts"
echo ""
echo "Usage:"
echo "${0} [-v] [-o output.mp3] feed_url"
echo " -v: verbose"
echo " -o: path of output file"
echo ""
}
# assume ready until proven otherwise
storytime_ready=true
verbose=false
output="output.mp3"
while getopts ":vo:h" opt; do
case ${opt} in
v) verbose="true" ;;
o) output="${OPTARG}" ;;
h) usage ;;
*) usage ;; # default
esac
done
shift $((OPTIND-1))
readonly verbose
readonly output
if check "cron" "crontab -l"; then
echo " Please install cron."
# if no arguments are passed, print usage and exit
if [[ $# -ne 1 ]]; then
usage
exit 1
fi
if check "mimic3" "mimic3 --version"; then
echo " Please install mimic3."
echo " Via pip: pip3 install mycroft-mimic3-tts[all]"
fi
main() {
local feed_url=$1
if check "ffmpeg 7" "ffmpeg -version | grep \"ffmpeg version 7\""; then
echo " Please install ffmpeg ~7."
fi
feed2exec parse ${feed_url} --output echo --args '{item.title}' | \
mimic3 --voice en_US/hifi-tts_low#92 --stdout | \
ffmpeg -y -i pipe:.wav -acodec pcm_s16le -ar 22050 -c:a libmp3lame ${output}
}
if check "feed2exec" "feed2exec"; then
echo " Please install feed2exec."
echo " Via pip: pip3 install feed2exec"
fi
# final check for readiness
if $storytime_ready; then
echo -e "\nReady for Storytime!"
else
echo -e "\nStorytime is not ready to go. Please install the missing dependencies."
fi
figlet "Fetching feed items."
figlet "Reading into an audio file."
figlet "Mixing video."
figlet "Uploading."
figlet "DONE!"
main $1