TransWikia.com

How to Speak in a foreign language?

Mathematica Asked by Timothy Wofford on January 7, 2021

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?

One Answer

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.

Correct answer by Timothy Wofford on January 7, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP