9
$\begingroup$

A previous question changed the pronunciation by changing the spelling of words or by externally changing the default system voice. This is useful for speaking in foreign languages too, but I don't want to do either of these things because sound correspondences might not exist (what is the English equivalent of the Spanish rolled R?) and toggling the default system voice manually is a pain.

Another related question changed the speed and pauses by inserting operating system specific markup into the spoken string for Windows systems, and a comment pointed to the documentation for OSX. From the accepted answer, it seems changing the voice is easy enough on Windows (I haven't tried it), but how do we do it on OSX? The documentation was not clear enough for me.

TL;DR

How can we get Speak to use a different voice?

$\endgroup$
1
  • 2
    $\begingroup$ On a related note, I asked a similar question about Speak on the Raspberry Pi. Turns out that the RPi version comes packaged with espeak and the configuration files can be tweaked as desired. I believe this solution is RPi specific, however. $\endgroup$ Oct 19, 2015 at 13:02

1 Answer 1

9
$\begingroup$

I let Mathematica parse the input into a speakable string, but then I send it to the operating system as if going through the command terminal. This allows me to set the voice flag for my installed voices.

mySpeak[input_, voice_String:"Allison", options:OptionsPattern[Speak]]:=
  CompoundExpression[
    Run["say -v " <> voice<>" " <> SpokenString[input, options]],
    Null
  ]

mySpeak["Hello, my name is Allison."]
mySpeak["Hola, me llamo Angelica.", "Angelica"]

The say command is available on OS X.

$\endgroup$
6
  • 2
    $\begingroup$ In another post related to the "related question" you cited above, I gave also an example with the say OS X specific speech engine ;) $\endgroup$
    – SquareOne
    Oct 19, 2015 at 13:26
  • 3
    $\begingroup$ On my system these voices are not installed by default, the voices Allison and Angelica have to be downloaded by selecting them under System Prefereces... | Dictation & Speech | System Voice | Customize... $\endgroup$
    – Bob Hanlon
    Oct 19, 2015 at 13:27
  • $\begingroup$ I would write this function as: mySpeak[input_, voice_String: "Alex", options : OptionsPattern[SpokenString]] := (Run["say -v " <> voice <> " " <> SpokenString[input, options]];). I would use "Alex" as the default voice because I am sure it is installed on all OS X systems. I would use the option pattern for SpokenString because that is function called, not Speak. $\endgroup$
    – m_goldberg
    Oct 19, 2015 at 14:41
  • $\begingroup$ @m_goldberg, mySpeak is supposed to replace Speak, so I think the options pattern should be that for Speak, but your point is taken. Perhaps the options should be Filtered for those that are compatible with SpokenString. $\endgroup$ Oct 19, 2015 at 15:08
  • $\begingroup$ If mySpeak is a replacement for Speak why doesn't it call Speak? $\endgroup$
    – m_goldberg
    Oct 19, 2015 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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