Mac OSX Text to Speech Batch

I have 300 English text files that I want to make into mp3 files to listen to as and when.

Is there a method, that I could use so that my Mac will batch text to speech the files to mp3 using a rotating voice from the free voices available on Mac OSX?


Solution 1:

You can use a shell command like this:

for f in *.txt;do say -f "$f" -o "${f%txt}aif";done

Random English voice:

IFS=$'\n';a=($(say -v\?|sed -E $'s/ {2,}/\t/'|awk -F$'\t' '$2~/^en_/{print $1}'));for f in *.txt;do say -v "${a[$((RANDOM%${#a[@]}))]}" -f "$f" -o "${f%txt}aif";done

Random voice from a list:

IFS=, read -a a<<<'Daniel,Fiona,Moira,Emily,Serena,Tessa';for f in *.txt;do say -v "${a[$((RANDOM%${#a[@]}))]}" -f "$f" -o "${f%txt}aif";done

You can use ffmpeg to convert the files to mp3:

for f in *.aif;do ffmpeg -i "$f" -aq 2 "${f%aif}mp3";done

-aq 2 corresponds to -V2 in lame. You can install ffmpeg with brew install ffmpeg after installing Homebrew.