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?


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.

| improve this answer | |
  • Wow. That looks like a neat, amazing solution. I will try it out. So far I have bought 3 apps from the appstore that cannot batch convert and rotate the voice! Thanks, thanks! – pommy Feb 4 '14 at 3:27
  • The first command works great. I just copied and pasted it into a command line after cd'ing into the relevant directory. Thank you.The second command to rotate the voices gives an error "Voice `Hysterical ' not found." but five lines of different voices not found as there are five txt files in the test folder. I only want to rotate among 6 specific voices (Daniel, Fiona, Moira, Emily, Serena and Tessa). Is there a way to specifiy those? Thanks again for your unbelievably simple solution that is much better than the paid apps that I have tried to use. – pommy Feb 4 '14 at 3:51
  • You're right, I got the same error. I edited the answer. – Lri Feb 4 '14 at 17:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.