Advertisement
API_nornorm

text to speech

Nov 18th, 2017
723
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.10 KB | None | 0 0
  1. local TextConverter = {
  2. LetterSounds = {
  3. ["a"] = {223757826, nil}; -- 203343899
  4. ["b"] = {223533700, 0.2}; -- 203344029
  5. ["c"] = {223533711, nil}; -- 203343994
  6. ["d"] = {223757910, nil}; -- 203398237
  7. ["e"] = {223758026, nil}; -- 203398295
  8. ["f"] = {223777655, nil}; -- 203398347
  9. ["g"] = {223777738, nil}; -- 203398372
  10. ["h"] = {223777757, nil}; -- 203398397
  11. ["i"] = {223777807, nil}; -- 203398422
  12. ["j"] = {223782888, nil}; -- 203398450
  13. ["k"] = {223533711, nil}; -- 203343994
  14. ["l"] = {223782961, 0.4}; -- 203398541
  15. ["m"] = {223782992, nil}; -- 203398578
  16. ["n"] = {223783063, nil}; -- 203398599
  17. ["o"] = {223783184, nil}; -- 203398611
  18. ["p"] = {223783235, nil}; -- 203398727
  19. ["q"] = {223783260, nil}; -- 203398755
  20. ["r"] = {223783305, 0.2}; -- 203398792
  21. ["s"] = {223783377, nil}; -- 203398806
  22. ["t"] = {223783446, nil}; -- 203398850
  23. ["u"] = {223783512, nil}; -- 203398872
  24. ["v"] = {223783654, nil}; -- 203398965
  25. ["w"] = {223783697, nil}; -- 203398984
  26. ["x"] = {223783796, nil}; -- 203399008
  27. ["y"] = {223783853, nil}; -- 203399043
  28. ["z"] = {223783893, nil}; -- 203399096
  29.  
  30. ["ch"] = {223784367, 0.3}; -- 203592149
  31. ["th"] = {223788235, 0.3}; -- 203399215
  32. ["sh"] = {223784505, 0.2}; -- 203399566
  33. ["wh"] = {223784555, 0.3}; -- 203622828
  34. ["oo"] = {223784456, 0.3}; -- 203399743
  35. ["ing"] = {223784393, 0.3}; -- 203402836
  36. };
  37.  
  38. LongVowels = {
  39. ["a"] = {223533687, nil}; -- 203343932
  40. ["e"] = {223777620, nil}; -- 203398314
  41. ["i"] = {223777855, nil}; -- 203398440
  42. ["o"] = {223783212, nil}; -- 203398619
  43. ["u"] = {223783572, nil}; -- 203398897
  44. };
  45.  
  46. Pronounce = {
  47. ["0"] = "zero";
  48. ["1"] = "wun";
  49. ["2"] = "too";
  50. ["3"] = "three";
  51. ["4"] = "four";
  52. ["5"] = "five";
  53. ["6"] = "six";
  54. ["7"] = "seven";
  55. ["8"] = "eyt";
  56. ["9"] = "nine";
  57. ["one"] = "wun";
  58. ["two"] = "too";
  59. ["eight"] = "eyt";
  60. ["eigh"] = "ey";
  61. ["gh"] = "h";
  62. ["kn"] = "n";
  63. ["come"] = "cu".."m";
  64. ["bye"] = "bi";
  65. ["#"] = "hashtag";
  66. ["@"] = "at";
  67. ["&"] = "and";
  68. ["*"] = "astrict";
  69. ["mn"] = "m";
  70. ["kn"] = "n";
  71. ["ies"] = "ees";
  72. };
  73.  
  74. NonEnglishRules = {
  75. ["to"] = "too";
  76. ["you"] = "yoo";
  77. ["we"] = "wee";
  78. ["are"] = "erh";
  79. ["your"] = "yoor";
  80. ["you're"] = "yoor";
  81. ["youre"] = "yoor";
  82. ["pizza"] = "peetzoh";
  83. ["ok"] = "okay";
  84. ["have"] = "hav";
  85. ["my"] = "mi";
  86. ["me"] = "mee";
  87. ["u"] = "yoo";
  88. ["r"] = "erh";
  89. ["move"] = "moov";
  90. ["dove"] = "duv";
  91. ["debris"] = "debree";
  92. ["do"] = "doo";
  93. }
  94. }
  95.  
  96.  
  97.  
  98. function IsSpacer(Input)
  99. if Input == " " or Input == "." or Input == "-" or Input == "," or Input == "?" or Input == "!" or Input == " " or Input == nil or Input == "" then
  100. return true
  101. else
  102. return false
  103. end
  104. end
  105.  
  106.  
  107. function ValidE(Input)
  108. if not Input then return nil end
  109. if string.lower(Input) == "e" or Input == "~" then
  110. return true
  111. else
  112. return false
  113. end
  114. end
  115.  
  116. function IsVowel(Input)
  117. Input = string.lower(tostring(Input))
  118. if Input == "a" or Input == "e" or Input == "i" or Input == "o" or Input == "u" then
  119. return true
  120. else
  121. return false
  122. end
  123. end
  124.  
  125. function ConvertText(Text)
  126. Text = string.lower(tostring(Text))
  127. local Letters = {}
  128. local IDs = {}
  129. for Rule,Replace in pairs(TextConverter.Pronounce) do
  130. Text = string.gsub(Text,string.lower(Rule),string.lower(Replace))
  131. end
  132. for Rule,Replace in pairs(TextConverter.NonEnglishRules) do
  133. local Start, End = string.find(Text, string.lower(Rule))
  134.  
  135. if Start and End and IsSpacer(string.sub(Text, Start-1, Start-1)) and IsSpacer(string.sub(Text, End+1, End+1)) then
  136. Text = string.gsub(Text, string.lower(Rule), Replace)
  137. end
  138. end
  139. for i = 1,#Text do
  140. table.insert(Letters, string.sub(Text,i,i))
  141. end
  142. for Num = 1,#Letters do
  143. if not Letters[Num] then break end
  144. local Letter = Letters[Num]
  145.  
  146. local function AddLetter()
  147. table.insert(IDs, TextConverter.LetterSounds[Letter])
  148. end
  149.  
  150. if Letter ~= "~" then
  151. if Letters[Num+1] and Letter..Letters[Num+1] == "oo" then -- moo
  152. table.insert(IDs, TextConverter.LetterSounds["oo"])
  153. table.remove(Letters, Num + 1)
  154. elseif Letters[Num+1] and Letter..Letters[Num+1] == "ou" then -- soup
  155. table.insert(IDs, TextConverter.LetterSounds["oo"])
  156. table.remove(Letters, Num + 1)
  157. elseif Letters[Num+1] and Letter..Letters[Num+1] == "th" then -- this
  158. table.insert(IDs, TextConverter.LetterSounds["th"])
  159. table.remove(Letters, Num + 1)
  160. elseif Letters[Num+1] and Letter..Letters[Num+1] == "sh" then -- shut
  161. table.insert(IDs, TextConverter.LetterSounds["sh"])
  162. table.remove(Letters, Num + 1)
  163. elseif Letters[Num+1] and Letter..Letters[Num+1] == "ee" then -- flee
  164. table.insert(IDs, TextConverter.LongVowels["e"])
  165. table.remove(Letters, Num + 1)
  166. elseif Letters[Num+1] and Letter..Letters[Num+1] == "wh" then -- what
  167. table.insert(IDs, TextConverter.LetterSounds["wh"])
  168. table.remove(Letters, Num + 1)
  169. elseif Letters[Num+1] and Letter..Letters[Num+1] == "ch" then -- chop
  170. table.insert(IDs, TextConverter.LetterSounds["ch"])
  171. table.remove(Letters, Num + 1)
  172. elseif Letters[Num+1] and Letter..Letters[Num+1] == "ph" then -- phone
  173. table.insert(IDs, TextConverter.LetterSounds["f"])
  174. table.remove(Letters, Num + 1)
  175. elseif Letters[Num+1] and Letter..Letters[Num+1] == "ng" then -- danger
  176. table.insert(IDs, TextConverter.LetterSounds[Num])
  177. Letters[Num + 1] = "j"
  178. elseif Letters[Num+1] and Letter..Letters[Num+1] == "ua" then -- lua
  179. table.insert(IDs, TextConverter.LetterSounds["oo"])
  180. elseif Letters[Num+1] and Letter..Letters[Num+1] == "ea" then -- peace
  181. table.insert(IDs, TextConverter.LongVowels["e"])
  182. table.remove(Letters, Num + 1)
  183. elseif Letters[Num+1] and Letter..Letters[Num+1] == "eo" then -- people
  184. table.insert(IDs, TextConverter.LongVowels["e"])
  185. table.remove(Letters, Num + 1)
  186. if ValidE(Letters[Num+4]) then Letters[Num+4] = "~" end
  187. elseif Letter == "c" and ValidE(Letters[Num+1]) then -- force
  188. table.insert(IDs, TextConverter.LetterSounds["s"])
  189. Letters[Num + 1] = "~"
  190. elseif Letter == string.lower(Letter) and IsVowel(Letter) and Letters[Num+1] and Letters[Num+2] and not IsSpacer(Letters[Num+1]) and ValidE(Letters[Num+2]) then -- like
  191. table.insert(IDs, TextConverter.LongVowels[Letter])
  192. Letters[Num + 2] = "~"
  193. elseif Letter == "i" and Letters[Num+1] and ValidE(Letters[Num+1]) and IsSpacer(Letters[Num+2]) then -- die
  194. table.insert(IDs, TextConverter.LongVowels["i"])
  195. Letters[Num + 1] = "~"
  196. elseif Letter == "o" and IsSpacer(Letters[Num+1]) then -- no
  197. table.insert(IDs, TextConverter.LongVowels["o"])
  198. elseif Letter == "i" and IsSpacer(Letters[Num+1]) then -- hi
  199. table.insert(IDs, TextConverter.LongVowels["i"])
  200. elseif Letters[Num+1] and IsSpacer(Letters[Num+2]) and Letter..Letters[Num+1] == "le" then -- bottle
  201. AddLetter()
  202. table.remove(Letters, Num + 1)
  203. elseif Letters[Num+1] and IsSpacer(Letters[Num+2]) and Letter..Letters[Num+1] == "el" then -- model
  204. Letters[Num] = "~"
  205. elseif Letters[Num+1] and Letters[Num+2] and Letter..Letters[Num+1] == "le" then -- bottle
  206. AddLetter()
  207. table.remove(Letters, Num + 1)
  208. elseif Letters[Num+1] and Letter..Letters[Num+1] == "qu" then --quick
  209. AddLetter()
  210. table.remove(Letters, Num + 1)
  211. elseif Letters[Num+1] == Letter then
  212. table.remove(Letters, Num)
  213. elseif Letters[Num+1] and Letter..Letters[Num+1] == "ck" then --click
  214. AddLetter()
  215. table.remove(Letters, Num)
  216. elseif IsVowel(Letter) and string.upper(Letter) == Letter then
  217. table.insert(IDs, TextConverter.LongVowels[string.lower(Letter)])
  218. elseif TextConverter.LetterSounds[Letter] then
  219. AddLetter()
  220. elseif IsSpacer(Letter) then
  221. table.insert(IDs, "Rest")
  222. end
  223. end
  224. end
  225.  
  226. return IDs
  227.  
  228.  
  229. end
  230. local NoSpeak = false
  231.  
  232. function MakeSound(Parent, ID, Volume, Pitch, Looped)
  233. if not Volume then Volume = 0.5 end
  234. if not Pitch then Pitch = 1 end
  235. if tonumber(ID) then ID = "rbxassetid://"..ID end
  236. if Looped == nil then Looped = false end
  237.  
  238. local Sound = Instance.new("Sound", Parent)
  239. Sound.Pitch = Pitch
  240. Sound.Volume = Volume
  241. Sound.SoundId = ID
  242. Sound.Looped = Looped
  243. return Sound
  244. end
  245.  
  246. function SayConvertedText(IDs, Parent)
  247. if not Parent then Parent = workspace end
  248. local Sounds = {}
  249. for _,Data in pairs(IDs) do
  250. if NoSpeak and Parent == workspace then
  251. break
  252. end
  253. local Length = 0.3
  254. if Data ~= "Rest" then
  255. local ID = Data[1]
  256. Length = Data[2]
  257.  
  258. local Sound = MakeSound(Parent, ID, 10, 1, false)
  259. Sound.Name = "SpeakSound"
  260. table.insert(Sounds, Sound)
  261. Sound:Play()
  262. if Length then
  263. coroutine.wrap(function()
  264. wait(Length)
  265. Sound:Stop()
  266. end)()
  267. end
  268. end
  269. if not Length then Length = 0.3 end
  270. wait(Length/2)
  271. end
  272. coroutine.wrap(function()
  273. wait(1)
  274. for _,Sound in pairs(Sounds) do
  275. Sound:Destroy()
  276. end
  277. end)()
  278. end
  279.  
  280.  
  281. local players = game:GetService("Players")
  282. local client = players.LocalPlayer
  283. local character = client.Character
  284. local head = character:WaitForChild("Head")
  285.  
  286. function onChatted(msg)
  287. SayConvertedText(ConvertText(msg), head)
  288. end
  289. client.Chatted:connect(onChatted)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement