Skip to content

Instantly share code, notes, and snippets.

@SingularReza
Created September 2, 2024 10:22
Show Gist options
  • Select an option

  • Save SingularReza/1eaabdb72ffe12ec862c224931d2c9fe to your computer and use it in GitHub Desktop.

Select an option

Save SingularReza/1eaabdb72ffe12ec862c224931d2c9fe to your computer and use it in GitHub Desktop.
A bash script to create WN audiobooks using edge-tts and the text file from whiteleaf's Narou.rb
#!/bin/bash
#requires edge-tts
#run in the same directory as the text file
read -p 'Enter the filename: ' TEXTFILE
read -p 'Enter voicetype (m/f) (default f): ' VOICE
# turn aozora formatted text into simple text file
perl -pe 's/[#.*?]//g' $TEXTFILE > TMP.txt
#split into chapters to overcome edge tts word limit
mkdir -p chapters && cd chapters
csplit ../TMP.txt '/第.*話/' '{*}'
#loop over each chapter file
FILENAME=""
for FILE in *; do
FILENAME=$(sed -n '1p' $FILE)
mv -f $FILE $FILENAME
echo $FILENAME
if [[ "$VOICE" == "m" ]]; then
edge-tts --voice ja-JP-KeitaNeural --text "$(cat $FILENAME)" --write-media $FILENAME.mp3 &
else
edge-tts --voice ja-JP-NanamiNeural --text "$(cat $FILENAME)" --write-media $FILENAME.mp3 &
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment