3
$\begingroup$

My aim is to make Mathematica speak out German words with Umlauts. I found a hint how to make use of a help function mySpeak that will forward a string to the say command and set the corresponding voice parameter.

However, I have not found a way to successfully forward Umlaut-letters from the notebook (or imported text file) through this mechanism to the say command. It seems that the InputForm formatting implicit of Run "breaks" the Umlaut encoding.

How can I send this exact string with appropriate and successful Umlaut encoding from Mathematica to the OS X terminal?

"say -v Anna öffentlich"

I used a line like this to see where it breaks:

Print[InputForm["say -v Anna öffentlich"]]

which returns:

"say -v Anna Ã[Paragraph]ffentlich"

where [Paragraph] is shown as a symbol.

$\endgroup$
  • 1
    $\begingroup$ Doesn't Speak["öffentlich"] work? $\endgroup$ – Karsten 7. Nov 17 '15 at 19:42
  • $\begingroup$ @Karsten7. I think it works fine, but my assumption is that the use of Run is important in this question for other reasons. $\endgroup$ – Jens Nov 17 '15 at 19:52
  • $\begingroup$ Correct. When using Speak the voice of the system settings has to be used. It cannot be configured. In my case the system setting is UK Englisch and I want the program to read out German language with a German voice setting on OS X $\endgroup$ – junis Nov 17 '15 at 21:21
  • $\begingroup$ I want to add that I am using version 10 and OS X 10.11.1 $\endgroup$ – junis Nov 18 '15 at 20:18
2
$\begingroup$

I don't know if Anna is pronouncing the umlaut correctly, but this result sounds very similar to what comes through the terminal to my tin ears:

In[1]:= RunProcess[{"say", "-v", "Anna", "öffentlich"}]
Out[1]= <|"ExitCode" -> 0, "StandardOutput" -> "", "StandardError" -> ""|>

There's clearly something weird going on with encodings here; using echo instead gives:

In[2]:= RunProcess[{"echo", "Ich öffentlich"}, "StandardOutput"] 
Out[2]= Ich öffentlich

The UTF-8 encoding for "ö" is C3 B6, while the character code codes for "Ã" and "¶" are C3 and B6 respectively in the "WindowsANSI"/"ISOLatin1" encodings, as well as the "Unicode" encoding.

$\endgroup$
  • 1
    $\begingroup$ This works fine in version 10. My approach is using Run and works in versions below 10 where RunProcess doesn't exist yet... (+1) $\endgroup$ – Jens Nov 17 '15 at 19:50
  • $\begingroup$ The weird encoding behaviour is exactly my problem. Is it on the mathematica side or on the OS X side? $\endgroup$ – junis Nov 18 '15 at 20:16
1
$\begingroup$

To get the umlaut into the Mac OS X command line properly, you could go the route via RTF export. Here is a function that automates this:

ClearAll[say];
Options[say] = {"Voice" -> "Zarvox"};

say[t_, OptionsPattern[]] := 
 Module[{out = 
    FileNameJoin[{$TemporaryDirectory, 
      "MathematicaOutput" <> StringJoin[Map[ToString, DateList[]]]}]},
   Export[out <> ".rtf", t];
  Run["textutil -convert txt " <> out <> ".rtf -output " <> out <> 
    ".txt && say -v " <> OptionValue["Voice"] <> " < " <> out <> 
    ".txt"];
  DeleteFile[{out <> ".txt", out <> ".rtf"}]]

say["öffentlich", "Voice" -> "Kathy"]

speaks with a bad english accent. Need to work on the "ch" sound... but umlaut works fine.

$\endgroup$

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.