Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question
1  
For the edit, don't use caps: WordData["smith","PhoneticForm"] –  ssch Sep 11 '13 at 20:11
add comment

1 Answer 1

up vote 9 down vote accepted

WordData can give you the IPA form of a word:

Gather[
 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.

Module[{
  ipapath = FileNames@FileNameJoin[
   {$UserBasePacletsDirectory,(*$ avoid SE indentation bug *)
    "Repository", "WordData_IPAPronunciation-*", "Data", "IPAPronunciation.wdx"}],
  iparules},
 If[Quiet[Head[WordData["a", "IPA"]] =!= WordData] ||
    ipapath == {} || ! FileExistsQ[Last@ipapath], 
    Return[$Failed, Module]];
 iparules = Dispatch[Append[
    Import[Last@ipapath][[2, 1]],
    _ -> Missing["NotAvailable"]]];
 Unprotect[WordData];
 WordData[word_String, "IPA"] := word /. iparules;
 DownValues[WordData] = RotateRight[DownValues[WordData]];
 Protect[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 be used as the second argument to Return on your 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.

share|improve this answer
    
Do you know of any way to get this to work approximately for different names? Smith, Williams, Johnson, Brees WordData["Smith","PhoneticForm"] –  Liam William Sep 11 '13 at 20:06
    
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. –  Liam William Sep 11 '13 at 20:12
1  
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. –  Rahul Narain Sep 11 '13 at 21:42
1  
@RahulNarain Strange as the data is still there in the paclet, see edit. (@Szabolcs ping) –  ssch Sep 11 '13 at 22:45
1  
@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. –  Szabolcs Sep 11 '13 at 23:41
show 4 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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