In this commit, the 'generate_mp3.sh' script has been refined to improve language selection and category order:
- Modified the 'lang_order' array to prioritize German ('de') over Spanish ('es-l') as the default language.
- Updated comments for better script documentation.
These changes aim to enhance the script's configurability and clarity, making it easier to customize language preferences and maintain the script in the long run.
82 lines
2.7 KiB
Bash
82 lines
2.7 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=("de" "es-l")
|
|
category_order=("date" "time" "weather")
|
|
|
|
# Create Directories
|
|
mkdir -p /sdcard/.mp3/
|
|
mkdir -p /sdcard/.text/
|
|
|
|
# Directories
|
|
txt_dir="/sdcard/.text"
|
|
mp3_dir="/sdcard/.mp3"
|
|
# remove old files
|
|
rm -f "$txt_dir"/*complete.txt
|
|
|
|
# open handout.html file
|
|
am start --user 0 -n org.bromite.chromium/org.chromium.chrome.browser.ChromeTabbedActivity -d content://pl.solidexplorer2.files/storage/emulated/0/.text/handout.html -t text/html
|
|
|
|
# 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
|