Initial commit

Added generate_mp3.sh script:
- Author: Michael Haider
- Created on: 26.01.2024
- Description: This script generates MP3 files from text files in German and Spanish using gtts-cli (Google Text-to-Speech).
- The script exports the path to the programs, defines language and category order, sets directories, and includes a function to create MP3 files.
- The generated MP3 files are created with gtts-cli in German or Spanish slow mode based on the file content.
- The script then sets the media volume and loops through categories and languages to play the generated MP3 files at normal or half speed, based on the language indication.
This commit is contained in:
Ratatoskr 2024-01-26 23:49:50 +01:00
parent 6d5ce74f08
commit e2b06dab34
Signed by: Ratatoskr
GPG Key ID: 28B77439A6D78F4E

73
generate_mp3.sh Normal file
View File

@ -0,0 +1,73 @@
#!/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"
# Function to create MP3 files
create_mp3_files() {
rm -f "$txt_dir"/*complete.txt
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