wecker/generate_mp3.sh
Ratatoskr b1390cb435
Enhance generate_mp3.sh script
- Add 'weather' to category_order array to include weather information in the generated MP3 files.
- Create directories /sdcard/.mp3/ and /sdcard/.text/ to store MP3 and text files respectively.
- Update txt_dir and mp3_dir paths to use /sdcard/ instead of /data/scripts/.
- Modify the 'am start' command to open handout.html in a Chromium tabbed activity for better compatibility.
- Remove unnecessary commented-out am start command and replace it with an updated command.
- Improve comments for better script understanding.
2024-02-08 15:59:47 +01:00

83 lines
2.8 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" "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.md file
#am start --user 0 -a android.intent.action.VIEW -d content://pl.solidexplorer2.files/storage/emulated/0/.text/handout.html -t text/html
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