# Implementing Dynamic Buttons for Phonetics

**URL:** <https://community.wolfram.com/t/implementing-dynamic-buttons-for-phonetics/10562>\
**Category:** Ideas\
**Tags:** education, fun-and-play, curated-data, interface-construction, computational-linguistics\
**Created:** [May 20, 2017, 11:15pm UTC](https://community.wolfram.com/t/implementing-dynamic-buttons-for-phonetics/10562 "2017-05-20T23:15:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![thalesfdfernandes](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/thalesfdfernandes/32/24924_2.png) [@thalesfdfernandes](https://community.wolfram.com/u/thalesfdfernandes)\
**Post date:** [May 20, 2017, 11:15pm UTC](https://community.wolfram.com/t/implementing-dynamic-buttons-for-phonetics/10562/1 "2017-05-20T23:15:07Z")

</div>

In a previous post of mine [Google Translate Structure](https://wolfram.discourse.group/t/10540/1) , I’ve shown how to a TextStructure-like box.  
In this post, I’ll show how can you create a button that changes dynamically when clicked (I didn’t find too many examples of it) to show the phonetic form of a word.

First, my MakeBox code slightly modified to allow IPA to work properly.

```
MakeBoxes[StructureElement[main_, down_], _] := GridBox[{
  {MakeBoxes@main}, {StyleBox[MakeBoxes@down, GrayLevel[0.6]]}},
  BaseStyle -> "TextElementGrid"]

```

Next, we need a simple function that outputs IPA, WordData can do this but not all words have phonetic form.

```
SetAttributes[{IPA, IPAQ, ButtomIPA}, Listable]

IPA[word_String] := IPA@word = Module[{list},
   If[StringCount[word, " "] != 0 \[Or] ! DictionaryWordQ@word, (* If it has space or is not in the dictionary *)
    Missing@word,
    (* WordData doesn't have IgnoreCase option... *)
    list = Select[WordData[]~Join~DictionaryLookup[], StringMatchQ[#, word, IgnoreCase -> True] &];
    If[Length@list == 0,
     Return@Missing@word,
     If[! MissingQ@#, ToString@#, Missing@word] &@
      WordData[First@list, "PhoneticForm"]
     ]
    ]
   ]

IPAQ[word_String] := IPAQ@word = !MissingQ@IPA@word

RemovePeriod[word_String] := StringTrim@StringReplace[word, "." | "," | "!" | "?" -> ""]

```

And finally, some code to create the Dynamic Button

```
ButtomIPA[word_String] := If[IPAQ@RemovePeriod@word,
  DynamicModule[{display = word, text = word, action = False},
   Button[Dynamic@display,
    If[StringQ@display,
     display = StructureElement[text, IPA@RemovePeriod@text],
     display = text
     ], Appearance -> None]
   ]
  ,
  Style[word, GrayLevel[0.5]]
  ]

```

A simple usage would be (sorry for the poor GIF quality):

```
Row@Riffle[ButtomIPA@StringSplit["My lord, the queen would speak with you, and presently.", Whitespace], " "]

```

![Video.gif](https://global.discourse-cdn.com/wolfram/original/3X/a/d/ad3c3abf71bb21c7b04df31fd258e313194d7262.gif)
