3

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?

bummi
  • 1,703
  • 4
  • 16
  • 28
pommy
  • 73
  • 8

2 Answers2

3

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.

Lri
  • 40,894
  • 7
  • 119
  • 157
  • 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 04 '14 at 03: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 04 '14 at 03:51
  • You're right, I got the same error. I edited the answer. – Lri Feb 04 '14 at 17:06
0

say -f "000.txt" -o "000.aiff"

f=txt file o=audio file (maybe output)

Needs to be aiff audio file and you'll have to convert I'm using macOS Ventura 13.0.1,

I used rtf file and it reads out the css first for some crazy reason

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 14 '22 at 17:18