//! English: how its words are said. //! //! English spelling is too irregular for rules alone, so a word is looked //! up first in a list of the words said most often (the commonest words of //! the language, and the ones a phone's settings and its screen reader say) //! and only read by the spelling rules when it is not there. The rules //! cover the regular patterns: a final silent e that lengthens the vowel //! before it ("made", "time"), the letter pairs (th, sh, ch, ph, ck, ng, //! ee, oo, ai, ou, igh, ...), the endings (-tion, -sion, -ture, -ous, -ed, //! -es) and the silent letters (kn, wr, mb). //! //! The accent is a plain General American one, the "r" said after vowels. //! The listed words carry their stress; a word read by rule is stressed on //! its first full vowel unless an ending such as "-tion" or "-ic" says the //! stress falls just before it. use alloc::vec::Vec; use crate::{Sound, phonemes, rules}; /// How each letter is said when a word is spelled out. const LETTERS: [&str; 26] = [ "'eI", "b 'i", "s 'i", "d 'i", "'i", "'E f", "dZ 'i", "'eI tS", "'aI", "dZ 'eI", "k 'eI", "'E l", "'E m", "'E n", "'oU", "p 'i", "k j 'u", "'A r", "'E s", "t 'i", "j 'u", "v 'i", "d 'V b @ l j u", "'E k s", "w 'aI", "z 'i", ]; /// The words read from this list rather than by rule. The little words /// that are never stressed in a sentence ("the", "of", "a") carry no mark. const WORDS: &[(&str, &str)] = &[ // The little words. ("a", "@"), ("an", "@ n"), ("the", "D @"), ("of", "@ v"), ("to", "t @"), ("and", "@ n d"), ("in", "I n"), ("is", "I z"), ("it", "I t"), ("it's", "I t s"), ("its", "I t s"), ("for", "f O r"), ("or", "O r"), ("as", "{ z"), ("at", "{ t"), ("by", "b aI"), ("be", "b i"), ("are", "A r"), ("was", "w V z"), ("were", "w 3"), ("from", "f r V m"), ("with", "w I D"), ("that", "D { t"), ("this", "D I s"), ("these", "D 'i z"), ("those", "D 'oU z"), ("there", "D E r"), ("their", "D E r"), ("they", "D eI"), ("them", "D E m"), ("then", "D E n"), ("than", "D { n"), ("he", "h i"), ("she", "S i"), ("we", "w i"), ("you", "j u"), ("your", "j O r"), ("you're", "j O r"), ("yours", "j 'O r z"), ("i", "aI"), ("i'm", "aI m"), ("me", "m i"), ("my", "m aI"), ("him", "h I m"), ("his", "h I z"), ("her", "h 3"), ("our", "aU 3"), ("us", "V s"), ("do", "d u"), ("does", "d V z"), ("have", "h { v"), ("has", "h { z"), ("had", "h { d"), ("will", "w I l"), ("would", "w U d"), ("could", "k U d"), ("should", "S U d"), ("can", "k { n"), ("into", "I n t u"), ("onto", "A n t u"), ("upon", "@ p A n"), ("if", "I f"), ("so", "s oU"), ("but", "b V t"), ("not", "n 'A t"), ("no", "n 'oU"), ("yes", "j 'E s"), ("too", "t 'u"), // Words whose spelling misleads. ("about", "@ b 'aU t"), ("above", "@ b 'V v"), ("account", "@ k 'aU n t"), ("again", "@ g 'E n"), ("against", "@ g 'E n s t"), ("all", "'O l"), ("allow", "@ l 'aU"), ("already", "O l r 'E d i"), ("also", "'O l s oU"), ("always", "'O l w eI z"), ("another", "@ n 'V D 3"), ("answer", "'{ n s 3"), ("any", "'E n i"), ("anything", "'E n i T I N"), ("apply", "@ p l 'aI"), ("around", "@ r 'aU n d"), ("away", "@ w 'eI"), ("because", "b I k 'O z"), ("been", "b 'I n"), ("before", "b I f 'O r"), ("being", "b 'i I N"), ("below", "b I l 'oU"), ("between", "b I t w 'i n"), ("both", "b 'oU T"), ("build", "b 'I l d"), ("bus", "b 'V s"), ("busy", "b 'I z i"), ("can't", "k '{ n t"), ("come", "k 'V m"), ("comes", "k 'V m z"), ("coming", "k 'V m I N"), ("computer", "k @ m p j 'u t 3"), ("country", "k 'V n t r i"), ("day", "d 'eI"), ("doing", "d 'u I N"), ("done", "d 'V n"), ("don't", "d 'oU n t"), ("double", "d 'V b @ l"), ("during", "d 'U r I N"), ("each", "'i tS"), ("early", "'3 l i"), ("either", "'i D 3"), ("else", "'E l s"), ("enough", "I n 'V f"), ("even", "'i v @ n"), ("ever", "'E v 3"), ("every", "'E v r i"), ("example", "I g z '{ m p @ l"), ("eye", "'aI"), ("father", "f 'A D 3"), ("few", "f j 'u"), ("four", "f 'O r"), ("friend", "f r 'E n d"), ("friends", "f r 'E n d z"), ("gas", "g '{ s"), ("get", "g 'E t"), ("give", "g 'I v"), ("given", "g 'I v @ n"), ("go", "g 'oU"), ("goes", "g 'oU z"), ("gone", "g 'O n"), ("good", "g 'U d"), ("goodbye", "g U d b 'aI"), ("great", "g r 'eI t"), ("group", "g r 'u p"), ("guide", "g 'aI d"), ("half", "h '{ f"), ("head", "h 'E d"), ("heard", "h '3 d"), ("hello", "h @ l 'oU"), ("here", "h 'I r"), ("house", "h 'aU s"), ("how", "h 'aU"), ("however", "h aU 'E v 3"), ("isn't", "'I z @ n t"), ("just", "dZ 'V s t"), ("know", "n 'oU"), ("known", "n 'oU n"), ("laugh", "l '{ f"), ("learn", "l '3 n"), ("live", "l 'I v"), ("long", "l 'O N"), ("love", "l 'V v"), ("many", "m 'E n i"), ("minus", "m 'aI n @ s"), ("money", "m 'V n i"), ("most", "m 'oU s t"), ("mother", "m 'V D 3"), ("move", "m 'u v"), ("much", "m 'V tS"), ("none", "n 'V n"), ("nothing", "n 'V T I N"), ("now", "n 'aU"), ("often", "'O f @ n"), ("once", "w 'V n s"), ("one", "w 'V n"), ("only", "'oU n l i"), ("other", "'V D 3"), ("own", "'oU n"), ("people", "p 'i p @ l"), ("plus", "p l 'V s"), ("put", "p 'U t"), ("really", "r 'I l i"), ("reply", "r I p l 'aI"), ("said", "s 'E d"), ("says", "s 'E z"), ("shown", "S 'oU n"), ("some", "s 'V m"), ("something", "s 'V m T I N"), ("study", "s t 'V d i"), ("social", "s 'oU S @ l"), ("sure", "S 'U r"), ("talk", "t 'O k"), ("thank", "T '{ N k"), ("thanks", "T '{ N k s"), ("though", "D 'oU"), ("thought", "T 'O t"), ("through", "T r 'u"), ("today", "t @ d 'eI"), ("together", "t @ g 'E D 3"), ("tomorrow", "t @ m 'A r oU"), ("touch", "t 'V tS"), ("two", "t 'u"), ("under", "'V n d 3"), ("until", "@ n t 'I l"), ("very", "v 'E r i"), ("want", "w 'A n t"), ("water", "w 'O t 3"), ("what", "w 'V t"), ("when", "w 'E n"), ("where", "w 'E r"), ("which", "w 'I tS"), ("who", "h 'u"), ("whole", "h 'oU l"), ("whose", "h 'u z"), ("why", "w 'aI"), ("woman", "w 'U m @ n"), ("women", "w 'I m I n"), ("won't", "w 'oU n t"), ("word", "w '3 d"), ("words", "w '3 d z"), ("work", "w '3 k"), ("world", "w '3 l d"), ("year", "j 'I r"), ("years", "j 'I r z"), // Numbers, and the words said with them. ("zero", "z 'I r oU"), ("three", "T r 'i"), ("five", "f 'aI v"), ("six", "s 'I k s"), ("seven", "s 'E v @ n"), ("eight", "'eI t"), ("nine", "n 'aI n"), ("ten", "t 'E n"), ("eleven", "I l 'E v @ n"), ("twelve", "t w 'E l v"), ("thirteen", "T 3 t 'i n"), ("fourteen", "f O r t 'i n"), ("fifteen", "f I f t 'i n"), ("sixteen", "s I k s t 'i n"), ("seventeen", "s E v @ n t 'i n"), ("eighteen", "eI t 'i n"), ("nineteen", "n aI n t 'i n"), ("twenty", "t w 'E n t i"), ("thirty", "T '3 t i"), ("forty", "f 'O r t i"), ("fifty", "f 'I f t i"), ("sixty", "s 'I k s t i"), ("seventy", "s 'E v @ n t i"), ("eighty", "'eI t i"), ("ninety", "n 'aI n t i"), ("hundred", "h 'V n d r @ d"), ("thousand", "T 'aU z @ n d"), ("million", "m 'I l j @ n"), ("point", "p 'OI n t"), ("percent", "p 3 s 'E n t"), ("equals", "'i k w @ l z"), ("hash", "h '{ S"), ("dollar", "d 'A l 3"), ("dollars", "d 'A l 3 z"), ("euro", "j 'U r oU"), ("euros", "j 'U r oU z"), ("pound", "p 'aU n d"), ("degrees", "d I g r 'i z"), ("dot", "d 'A t"), // What a phone says: its settings, its apps, its screen reader. ("settings", "s 'E t I N z"), ("setting", "s 'E t I N"), ("language", "l '{ N g w I dZ"), ("languages", "l '{ N g w I dZ I z"), ("accessibility", "{ k s E s @ b 'I l I t i"), ("accessible", "{ k s 'E s @ b @ l"), ("contrast", "k 'A n t r { s t"), ("screen", "s k r 'i n"), ("reader", "r 'i d 3"), ("read", "r 'i d"), ("button", "b 'V t @ n"), ("buttons", "b 'V t @ n z"), ("switch", "s w 'I tS"), ("heading", "h 'E d I N"), ("on", "'A n"), ("off", "'O f"), ("wi-fi", "w 'aI f aI"), ("wifi", "w 'aI f aI"), ("network", "n 'E t w 3 k"), ("networks", "n 'E t w 3 k s"), ("notification", "n oU t @ f @ k 'eI S @ n"), ("notifications", "n oU t @ f @ k 'eI S @ n z"), ("home", "h 'oU m"), ("close", "k l 'oU z"), ("back", "b '{ k"), ("change", "tS 'eI n dZ"), ("password", "p '{ s w 3 d"), ("device", "d I v 'aI s"), ("devices", "d I v 'aI s I z"), ("bluetooth", "b l 'u t u T"), ("update", "'V p d eI t"), ("updates", "'V p d eI t s"), ("agent", "'eI dZ @ n t"), ("size", "s 'aI z"), ("text", "t 'E k s t"), ("larger", "l 'A r dZ 3"), ("large", "l 'A r dZ"), ("high", "h 'aI"), ("use", "j 'u z"), ("english", "'I N g l I S"), ("dutch", "d 'V tS"), ("nederlands", "n 'eI d 3 l @ n d z"), ("menu", "m 'E n j u"), ("open", "'oU p @ n"), ("cancel", "k '{ n s @ l"), ("ok", "oU k 'eI"), ("okay", "oU k 'eI"), ("save", "s 'eI v"), ("delete", "d I l 'i t"), ("edit", "'E d I t"), ("search", "s '3 tS"), ("battery", "b '{ t @ r i"), ("volume", "v 'A l j u m"), ("brightness", "b r 'aI t n @ s"), ("sound", "s 'aU n d"), ("display", "d I s p l 'eI"), ("keyboard", "k 'i b O r d"), ("phone", "f 'oU n"), ("call", "k 'O l"), ("calls", "k 'O l z"), ("message", "m 'E s I dZ"), ("messages", "m 'E s I dZ I z"), ("contact", "k 'A n t { k t"), ("contacts", "k 'A n t { k t s"), ("camera", "k '{ m @ r @"), ("photos", "f 'oU t oU z"), ("music", "m j 'u z I k"), ("clock", "k l 'A k"), ("time", "t 'aI m"), ("date", "d 'eI t"), ("alarm", "@ l 'A r m"), ("calendar", "k '{ l @ n d 3"), ("file", "f 'aI l"), ("files", "f 'aI l z"), ("folder", "f 'oU l d 3"), ("app", "'{ p"), ("apps", "'{ p s"), ("application", "{ p l @ k 'eI S @ n"), ("system", "s 'I s t @ m"), ("version", "v '3 Z @ n"), ("storage", "s t 'O r I dZ"), ("memory", "m 'E m @ r i"), ("privacy", "p r 'aI v @ s i"), ("security", "s @ k j 'U r @ t i"), ("location", "l oU k 'eI S @ n"), ("connected", "k @ n 'E k t I d"), ("connect", "k @ n 'E k t"), ("disconnected", "d I s k @ n 'E k t I d"), ("available", "@ v 'eI l @ b @ l"), ("unavailable", "V n @ v 'eI l @ b @ l"), ("enabled", "I n 'eI b @ l d"), ("disabled", "d I s 'eI b @ l d"), ("selected", "s @ l 'E k t I d"), ("select", "s @ l 'E k t"), ("checked", "tS 'E k t"), ("unchecked", "V n tS 'E k t"), ("link", "l 'I N k"), ("image", "'I m I dZ"), ("list", "l 'I s t"), ("item", "'aI t @ m"), ("items", "'aI t @ m z"), ("page", "p 'eI dZ"), ("window", "w 'I n d oU"), ("tab", "t '{ b"), ("dialog", "d 'aI @ l O g"), ("field", "f 'i l d"), ("slider", "s l 'aI d 3"), ("level", "l 'E v @ l"), ("speech", "s p 'i tS"), ("voice", "v 'OI s"), ("speed", "s p 'i d"), ("pitch", "p 'I tS"), ("faster", "f '{ s t 3"), ("slower", "s l 'oU 3"), ("next", "n 'E k s t"), ("previous", "p r 'i v i @ s"), ("first", "f '3 s t"), ("last", "l '{ s t"), ("up", "'V p"), ("down", "d 'aU n"), ("left", "l 'E f t"), ("right", "r 'aI t"), ("top", "t 'A p"), ("bottom", "b 'A t @ m"), ("start", "s t 'A r t"), ("stop", "s t 'A p"), ("play", "p l 'eI"), ("pause", "p 'O z"), ("new", "n 'u"), ("more", "m 'O r"), ("less", "l 'E s"), ("show", "S 'oU"), ("hide", "h 'aI d"), ("deny", "d I n 'aI"), ("press", "p r 'E s"), ("tap", "t '{ p"), ("hold", "h 'oU l d"), ("swipe", "s w 'aI p"), ("scroll", "s k r 'oU l"), ("zoom", "z 'u m"), ("user", "j 'u z 3"), ("sign", "s 'aI n"), ("out", "'aU t"), ("lock", "l 'A k"), ("unlock", "V n l 'A k"), ("restart", "r i s t 'A r t"), ("power", "p 'aU 3"), ("airplane", "'E r p l eI n"), ("mode", "m 'oU d"), ("dark", "d 'A r k"), ("light", "l 'aI t"), ("theme", "T 'i m"), ("colour", "k 'V l 3"), ("color", "k 'V l 3"), ("colours", "k 'V l 3 z"), ("font", "f 'A n t"), ("bold", "b 'oU l d"), ("small", "s m 'O l"), ("medium", "m 'i d i @ m"), ("normal", "n 'O r m @ l"), ("default", "d 'i f O l t"), ("reset", "r i s 'E t"), ("install", "I n s t 'O l"), ("installed", "I n s t 'O l d"), ("download", "d 'aU n l oU d"), ("downloading", "d 'aU n l oU d I N"), ("loading", "l 'oU d I N"), ("error", "'E r 3"), ("warning", "w 'O r n I N"), ("failed", "f 'eI l d"), ("please", "p l 'i z"), ("wait", "w 'eI t"), ("try", "t r 'aI"), ("welcome", "w 'E l k @ m"), ("person", "p '3 s @ n"), ("mail", "m 'eI l"), ("email", "'i m eI l"), ("e-mail", "'i m eI l"), ("internet", "'I n t 3 n E t"), ("online", "'A n l aI n"), ("offline", "'O f l aI n"), ("signal", "s 'I g n @ l"), ("mobile", "m 'oU b @ l"), ("data", "d 'eI t @"), ("store", "s t 'O r"), ("browser", "b r 'aU z 3"), ("web", "w 'E b"), ("map", "m '{ p"), ("maps", "m '{ p s"), ("weather", "w 'E D 3"), ("yesterday", "j 'E s t 3 d eI"), ("monday", "m 'V n d eI"), ("tuesday", "t 'u z d eI"), ("wednesday", "w 'E n z d eI"), ("thursday", "T '3 z d eI"), ("friday", "f r 'aI d eI"), ("saturday", "s '{ t 3 d eI"), ("sunday", "s 'V n d eI"), ("january", "dZ '{ n j u E r i"), ("february", "f 'E b r u E r i"), ("march", "m 'A r tS"), ("april", "'eI p r @ l"), ("may", "m 'eI"), ("june", "dZ 'u n"), ("july", "dZ u l 'aI"), ("august", "'O g @ s t"), ("september", "s E p t 'E m b 3"), ("october", "A k t 'oU b 3"), ("november", "n oU v 'E m b 3"), ("december", "d I s 'E m b 3"), ("hour", "'aU 3"), ("hours", "'aU 3 z"), ("minute", "m 'I n I t"), ("minutes", "m 'I n I t s"), ("second", "s 'E k @ n d"), ("seconds", "s 'E k @ n d z"), ("week", "w 'i k"), ("month", "m 'V n T"), ("pinnacle", "p 'I n @ k @ l"), ("share", "S 'E r"), ("send", "s 'E n d"), ("copy", "k 'A p i"), ("paste", "p 'eI s t"), ("cut", "k 'V t"), ("undo", "V n d 'u"), ("redo", "r i d 'u"), ("options", "'A p S @ n z"), ("information", "I n f 3 m 'eI S @ n"), ("help", "h 'E l p"), ("quit", "k w 'I t"), ("exit", "'E g z I t"), ("enter", "'E n t 3"), ("space", "s p 'eI s"), ("return", "r I t '3 n"), ("escape", "I s k 'eI p"), ("shift", "S 'I f t"), ("control", "k @ n t r 'oU l"), ("key", "k 'i"), ("keys", "k 'i z"), ("gesture", "dZ 'E s tS 3"), ("gestures", "dZ 'E s tS 3 z"), ("captions", "k '{ p S @ n z"), ("motion", "m 'oU S @ n"), ("animations", "{ n @ m 'eI S @ n z"), ("vibration", "v aI b r 'eI S @ n"), ("feedback", "f 'i d b { k"), ("silent", "s 'aI l @ n t"), ("mute", "m j 'u t"), ("speaker", "s p 'i k 3"), ("headphones", "h 'E d f oU n z"), ("microphone", "m 'aI k r @ f oU n"), ("permissions", "p 3 m 'I S @ n z"), ("charging", "tS 'A r dZ I N"), ("full", "f 'U l"), ("empty", "'E m p t i"), ("low", "l 'oU"), ("pin", "p 'I n"), ("code", "k 'oU d"), ("fingerprint", "f 'I N g 3 p r I n t"), ("wallpaper", "w 'O l p eI p 3"), ("status", "s t 'eI t @ s"), ("focus", "f 'oU k @ s"), ]; /// The spelling rules, letter by letter, special cases first (see /// [`crate::rules`] for how they are written). const RULES: &[&str] = &[ // a " [a] =@", " [are] =A r", "w[a]tch=A", "w[a]nt=A", "w[a]sh=A", "qu[a]l=A", "qu[a]n=A", " [ar]o=@ r", "[ar]#=E r", "^[as]#=eI s", "[a]wa=@", "[aw]=O", " :[any]=E n i", "[a]^+#=eI", "[a]^y =eI", "#:[ally]=@ l i", " [al]#=@ l", "[again]=@ g E n", "#:[ag]e=I dZ", "[a]^%=eI", "[a]^+:#={", "[arr]=@ r", " :[ar] =A r", "[ar] =3", "[ar]=A r", "[air]=E r", "[ai]=eI", "[ay]=eI", "[au]=O", "#:[al] =@ l", "#:[als] =@ l z", "[alk]=O k", "[all]=O l", "[alm]=A m", " :[able]=eI b @ l", "[able]=@ b @ l", "[ang]+=eI n dZ", "[a]={", // b " [be]^#=b I _", "[being]=b i I N", "[bb]=b", "m[b] =", "[b]=b", // c "[ch]r=k", "s[ch]=k", "[ch]=tS", "[cia]l=~ S @", "[cian]=~ S @ n", "[cious]=~ S @ s", "[cc]+=k s", "[cc]=k", "[ck]=k", "[c]+=s", "[c]=k", // d " [de]^#=d I _", "[dg]=dZ", "[dd]=d", "[d]=d", // e "#:t[ed] =I d", "#:d[ed] =I d", "#:p[ed] =t", "#:k[ed] =t", "#:ss[ed] =t", "#:c[ed] =t", "#:x[ed] =t", "#:h[ed] =t", "#:f[ed] =t", "#:[ed] =d", "&[es] =I z", "#:p[es] =s", "#:k[es] =s", "#:t[es] =s", "#:f[es] =s", "#:[es] =z", "#:[e]ly =", "#:^[e]ful=", "#:^[e]ment=", "#:[e] =", " :[e] =i", "@[ew]=u", "[ew]=j u", "[eer]=I r", "[ee]=i", "[ear]^=3", "[ear]=I r", "h[ea]d=E", "r[ea]dy=E", "[ea]lth=E", "[ea]ther=E", "[ea]=i", "[eigh]=eI", "c[ei]=i", "[ei]=eI", "[ey] =i", "[ey]=eI", "[eu]=j u", "[er]#=E r", "[er]=3", "[e]^e =i", " [ex]#=I g z _", "#:[en] =@ n", "#:[el] =@ l", "[e]=E", // f "[ful] =f @ l", "[ff]=f", "[f]=f", // g " [gh]=g", "#[gh]=", "[g]n =", "[g]ns =", "[gg]=g", " [g]et=g", " [g]iv=g", " [g]ir=g", " [g]if=g", "[g]+=dZ", "[g]=g", // h "[h]#=h", "[h]=", // i " [in]=I n", " [i] =aI", "[in]d =aI n", "[ier]=i 3", "#:r[ied] =i d", "[ied] =aI d", "#:[ie] =i", "[ie] =aI", "#:[ies] =i z", "[ies] =aI z", "[ie]=i", "[igh]=aI", "[ild]=aI l d", "[ign] =aI n", "[igns] =aI n z", "[ique]='i k", "#:[ic] =~ I k", "#:[ics] =~ I k s", "#:[ical]=~ I k @ l", "#:[ity] =~ I t i", "#:[ion]=~ j @ n", "[ire] =aI 3", "[ir]#=aI r", "[ir]=3", "[iz]%=aI z", "[is]%=aI z", "#:[is] =I s", "#:[ice] =I s", "#:[ine] =I n", "#:[ive] =I v", "[i]^%=aI", "[i]=I", // j "[j]=dZ", // k " [k]n=", "[k]=k", // l "[ll]=l", "#:^[le] =@ l", "[l]=l", // m "[mm]=m", "[ment] =m @ n t", "[ments] =m @ n t s", "[mb] =m", "[m]=m", // n "[nn]=n", "[nge] =n dZ", "[nges] =n dZ I z", "[ng]=N", "[nk]=N k", "[n]=n", // o "[of] =@ v", "[ough]t=O", "[ough]=V f", "#:[or] =3", "[or]=O r", "[oo]k=U", "[ood]=U d", "[oor]=O r", "[oo]=u", "[oar]=O r", "[oa]=oU", "[oi]=OI", "[oy]=OI", "#:[ous]=@ s", "[ould]=U d", "[ou]=aU", " [own]=oU n", "[own]=aU n", "[ow]e=aU", "[ow]=oU", "[oth]er=V D", "[old]=oU l d", "[o]^%=oU", "[o] =oU", "#:[on] =@ n", "[o]=A", // p "[ph]=f", "[pp]=p", " [ps]=s", " [pre]^#=p r I _", "[p]=p", // q "[qu]=k w", "[q]=k", // r " [re]^#=r I _", "[rr]=r", " [rh]=r", "[r]=r", // s "[sh]=S", "#[sion]=~ Z @ n", "[sion]=~ S @ n", "#[sure]=Z 3", "[sure]=S 3", "#[sual]=Z u @ l", "[sch]=s k", "[ss]=s", "#[s]#=z", ".[s] =z", "#[s] =z", "[s]=s", // t "s[tion]=~ tS @ n", "[tion]=~ S @ n", "[tial]=~ S @ l", "[tient]=~ S @ n t", "[tious]=~ S @ s", "[ture]=tS 3", "#[th]er=D", "[th]=T", "[tch]=tS", "[tt]=t", "[t]=t", // u " [un]i=j u n", " [un]=V n", "@[ue] =u", "[ue] =j u", "#:[us] =@ s", "@[ur]#=U r", "[ur]#=j U r", "[ur]=3", "[u]^ =V", "[u]^^=V", "@[u]=u", "[u]^#=j u", "[u]=V", // v "[v]=v", // w "[wh]o=h", "[wh]=w", "[wr]=r", "[wor]^=w 3", "[w]=w", // x " [x]=z", "[x]=k s", // y " [y]#=j", " :[y] =aI", "[y]^%=aI", "#:[y] =i", "[y]=I", // z "[zz]=z", "[z]=z", ]; /// The sounds of `word` if it is one of the listed words. pub fn lookup(word: &str) -> Option> { WORDS .iter() .find(|(w, _)| *w == word) .map(|(_, said)| phonemes::sounds(said, false)) } /// The sounds of `word`, lowercase letters only, by the spelling rules. pub fn by_rule(word: &str) -> Vec { phonemes::sounds(&rules::read(word, RULES), true) } /// The name of the letter `c`, as a word is spelled out. pub fn letter(c: u8) -> Vec { let i = usize::from(c.saturating_sub(b'a')).min(25); phonemes::sounds(LETTERS[i], true) } #[cfg(test)] mod tests { extern crate std; use super::*; use alloc::string::String; fn said(word: &str) -> String { let sounds = lookup(word).unwrap_or_else(|| by_rule(word)); let mut out = String::new(); phonemes::write(&sounds, &mut out); out } #[test] fn every_entry_is_written_in_known_symbols() { for (word, written) in WORDS { assert!(phonemes::all_known(written), "{word}: {written}"); } for written in LETTERS { assert!(phonemes::all_known(written), "{written}"); } assert!(rules::all_parse(RULES)); for rule in RULES { let sounds = &rule[rule.find('=').unwrap() + 1..]; assert!(phonemes::all_known(sounds), "{rule}"); } let mut words: std::vec::Vec<&str> = WORDS.iter().map(|(w, _)| *w).collect(); words.sort_unstable(); let before = words.len(); words.dedup(); assert_eq!(words.len(), before, "a word listed twice"); } #[test] fn listed_words() { assert_eq!(said("settings"), "s 'E t I N z"); assert_eq!(said("button"), "b 'V t @ n"); assert_eq!(said("the"), "D @"); assert_eq!(said("screen"), "s k r 'i n"); assert_eq!(said("reader"), "r 'i d 3"); } #[test] fn words_by_rule() { assert_eq!(said("make"), "m 'eI k"); assert_eq!(said("station"), "s t 'eI S @ n"); assert_eq!(said("night"), "n 'aI t"); assert_eq!(said("basic"), "b 'eI s I k"); assert_eq!(said("phone"), "f 'oU n"); assert_eq!(said("shop"), "S 'A p"); assert_eq!(said("thing"), "T 'I N"); assert_eq!(said("knife"), "n 'aI f"); assert_eq!(said("wrote"), "r 'oU t"); assert_eq!(said("played"), "p l 'eI d"); assert_eq!(said("wanted"), "w 'A n t I d"); assert_eq!(said("stopped"), "s t 'A p t"); assert_eq!(said("picture"), "p 'I k tS 3"); assert_eq!(said("nervous"), "n '3 v @ s"); assert_eq!(said("rain"), "r 'eI n"); assert_eq!(said("boat"), "b 'oU t"); assert_eq!(said("feet"), "f 'i t"); assert_eq!(said("decision"), "d I s 'I Z @ n"); assert_eq!(said("quick"), "k w 'I k"); assert_eq!(said("lamb"), "l '{ m"); assert_eq!(said("boxes"), "b 'A k s I z"); assert_eq!(said("electric"), "E l 'E k t r I k"); } #[test] fn letters_are_named() { let mut out = String::new(); phonemes::write(&letter(b'w'), &mut out); assert_eq!(out, "d 'V b @ l j u"); } }