Is there a way to get a word's linguistic pronunciation given the word as a string?

I would like a function LingusticPronunciation such that, for example, LingusticPronunciation["Dog"] would return "Dawg" or maybe even "dȯg" or "däg", depending on what type of pronunciation dictionary is used.

Ultimately I am trying to search for all homophones in a document and would prefer not having to use the internet to check for different homophone/pronunciation information.

  • 1
    $\begingroup$ For the edit, don't use caps: WordData["smith","PhoneticForm"] $\endgroup$ – ssch Sep 11 '13 at 20:11

WordData can give you the IPA form of a word:

 WordData[#, "PhoneticForm"] & /@ {"pray", "prey", "wade", "weighed"}
(* {{"pr'ey", "pr'ey"}, {"w'eyd", "w'eyd"}} *)

EDIT It seems WordData[word, "PhoneticForm"] no longer provides the proper IPA, however that data is still included in the paclet so we can make a new WordData property for that. (or override the the current PhoneticForm)

The IPA data is stored in a file called "IPAPronunciation.wdx" which contains a dispatch table with the "word"->"ipa" rules. It does not contain a _ -> Missing["NotAvailable"] so that is added.

  ipapath = FileNames@FileNameJoin[
   {$UserBasePacletsDirectory,(*$ avoid SE indentation bug *)
    "Repository", "WordData_IPAPronunciation-*", "Data", "IPAPronunciation.wdx"}],
 If[Quiet[Head[WordData["a", "IPA"]] =!= WordData] ||
    ipapath == {} || ! FileExistsQ[Last@ipapath], 
    Return[$Failed, Module]];
 iparules = Dispatch[Append[
    Import[Last@ipapath][[2, 1]],
    _ -> Missing["NotAvailable"]]];
 WordData[word_String, "IPA"] := word /. iparules;
 DownValues[WordData] = RotateRight[DownValues[WordData]];
WordData[#, "IPA"] & /@ {"pray", "prey", "wade", "weighed"}
(* {"prˈeɪ", "prˈeɪ", "wˈeɪd", "wˈeɪd"} *)

Some things used in above code:

Overloading second argument of CountryData

What can I use as the second argument to Return in my own functions?

If there is a neat way to add a rule to a dispatch table without redoing the Dispatch call feel free to edit.

  • $\begingroup$ Do you know of any way to get this to work approximately for different names? Smith, Williams, Johnson, Brees WordData["Smith","PhoneticForm"] $\endgroup$ – William Sep 11 '13 at 20:06
  • $\begingroup$ That is a very interesting link. It appears the following works for names WordData[ToLowerCase@"Smith", "PhoneticForm"] although I am not sure how accurate it is. $\endgroup$ – William Sep 11 '13 at 20:12
  • 1
    $\begingroup$ The documentation says it returns IPA, and the examples in the documentation are in IPA, but the actual values Mathematica returns in practice are not in IPA. The IPA for your words should be /preɪ/ and /weɪd/ instead; see e.g. Wikipedia's IPA key. $\endgroup$ – Rahul Sep 11 '13 at 21:42
  • 1
    $\begingroup$ @RahulNarain Strange as the data is still there in the paclet, see edit. (@Szabolcs ping) $\endgroup$ – ssch Sep 11 '13 at 22:45
  • 1
    $\begingroup$ @Liam ... even if you have never seen that word before, but you need to know "how English pronunciation works" (to put it simply). All these transcriptions work only with the added knowledge that the language being transcribed is English. $\endgroup$ – Szabolcs Sep 11 '13 at 23:41

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.