From 2badabb616c7df2535961c3ed2f622e240936799 Mon Sep 17 00:00:00 2001 From: Ratatoskr Date: Mon, 29 Jan 2024 13:31:29 +0100 Subject: [PATCH] Refactor script to generate MP3 files In this commit, I made several improvements to the 'generate_mp3.sh' script: 1. Removed old complete files before processing to ensure a clean slate. 2. Modified the 'create_mp3_files' function to use '>>' instead of '>' when appending text to the complete files. 3. Updated the comments in the script for better clarity. These changes help maintain a more organized and reliable MP3 generation process. The script now properly appends text to the 'de_complete.txt' and 'es_complete.txt' files, and it removes old complete files before starting the processing. File Changes: - Modified 'generate_mp3.sh' (see diff for details) Note: Please review and test the changes to ensure they meet your requirements. --- generate_mp3.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/generate_mp3.sh b/generate_mp3.sh index 927d351..461959f 100644 --- a/generate_mp3.sh +++ b/generate_mp3.sh @@ -20,9 +20,11 @@ category_order=("date" "time") txt_dir="/data/scripts/.text" mp3_dir="/data/scripts/.mp3" +# remove old files +rm -f "$txt_dir"/*complete.txt + # 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 @@ -31,12 +33,12 @@ create_mp3_files() { 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 "$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 "$text" >> "$txt_dir/es_complete.txt" echo "Spanish MP3 file created: $base_filename.mp3" else echo "File $file was not processed"