wecker/generate_mp3.sh
Ratatoskr 0fb0ae1e48
Refactor directory comment, update file opening command, and improve German MP3 creation comment in generate_mp3.sh:
- Refactored a directory comment in the script for clarity.
- Updated the file opening command to use the correct path (/sdcard/handout.html).
- Improved the comment explaining the creation of German MP3 files.
2024-02-06 17:38:20 +01:00

78 lines
2.5 KiB
Bash

#!/bin/sh
#######################################
# generate_mp3.sh - Generates MP3 files from text files in German and Spanish
#
# Author: Michael Haider
# Created on: 26.01.2024
# Description: This script creates MP3 files from text files in German and Spanish
# using gtts-cli (Google Text-to-Speech).
#######################################
# Export the path to the programs
export PATH=$PATH:/data/data/com.termux/files/usr/bin
# Array with the desired languages in order
lang_order=("es" "de" "es-l")
category_order=("date" "time")
# Directories
txt_dir="/data/scripts/.text"
mp3_dir="/data/scripts/.mp3"
# remove old files
rm -f "$txt_dir"/*complete.txt
# open handout.md file
am start --user 0 -a android.intent.action.VIEW -d file:///sdcard/handout.html -t text
# Function to create MP3 files
create_mp3_files() {
for file in "$txt_dir"/*.txt; do
text=$(cat "$file") # Read the content of the file
base_filename=$(basename "$file" .txt) # File name without path and extension
if [[ $file == *de.txt ]]; then
# If it's a German file, create a German MP3
/data/data/com.termux/files/usr/bin/gtts-cli -l de "$text" --output "$mp3_dir/$base_filename.mp3"
echo "$text" >> "$txt_dir/de_complete.txt"
echo "German MP3 file created: $base_filename.mp3"
elif [[ $file != *de.txt ]]; then
# If it's a Spanish file, create a Spanish MP3 in slow mode
/data/data/com.termux/files/usr/bin/gtts-cli -l es -s "$text" --output "$mp3_dir/$base_filename.mp3"
echo "$text" >> "$txt_dir/es_complete.txt"
echo "Spanish MP3 file created: $base_filename.mp3"
else
echo "File $file was not processed"
fi
done
}
# Call the function to create the MP3 files
create_mp3_files
# Set media volume
cmd media_session volume --set 10 --stream 9
# Loop through categories and languages
for category in "${category_order[@]}"; do
echo "All categories: ${category_order[@]}"
echo "Actual category: $category"
for language in "${lang_order[@]}"; do
echo "All languages: ${lang_order[@]}"
echo "Actual language: $language"
echo "Actual file: ${category}_${language}.mp3"
# Check if the language indicates slower playback
if [[ $language == *"-l"* ]]; then
# If "-l" is present in lang_order, play the file at half speed
lang_without_l="${language/-l/}" # Remove "-l" from the language
mpv --speed=0.8 "$mp3_dir/${category}_${lang_without_l}.mp3"
else
# Otherwise, play the file at normal speed
mpv "$mp3_dir/${category}_${language}.mp3"
fi
done
done