SHARE
TWEET

Untitled

a guest May 12th, 2017 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- SERVER
  2.  
  3. function convertTextToSpeech(text, broadcastTo, lang)
  4.     -- Ensure first argument is valid
  5.     assert(type(text) == "string", "Bad argument 1 @ convertTextToSpeech [ string expected, got " .. type(text) .. "]")
  6.     assert(#text <= 100, "Bad argument 1 @ convertTextToSpeech [ too long string; 100 characters maximum ]")
  7.     if triggerClientEvent then -- Is this function called serverside?
  8.         -- Ensure second and third arguments are valid
  9.         assert(broadcastTo == nil or type(broadcastTo) == "table" or isElement(broadcastTo), "Bad argument 2 @ convertTextToSpeech [ table/element expected, got " .. type(broadcastTo) .. "]")
  10.         assert(lang == nil or type(lang) == "string", "Bad argument 3 @ convertTextToSpeech [ string expected, got " .. type(lang) .. "]")
  11.         -- Tell the client to play the speech
  12.         return triggerClientEvent(broadcastTo or root, "playTTS", root, text, lang or "en")
  13.     else -- This function is executed clientside
  14.         local lang = broadcastTo
  15.         -- Ensure second argument is valid
  16.         assert(lang == nil or type(lang) == "string", "Bad argument 2 @ convertTextToSpeech [ string expected, got " .. type(lang) .. "]")
  17.         return playTTS(text, lang or "en")
  18.     end
  19. end
  20.  
  21. function testSpeech ( player, cmd )
  22.     convertTextToSpeech("Dziękować", player, "pl")
  23.     outputChatBox("SERVERSIEDE OK")
  24. end
  25. addCommandHandler ( "testing", testSpeech )
  26.  
  27.  
  28. -- CLIENT
  29.  
  30. addEvent("playTTS", true) -- Add the event
  31.  
  32. local function playTTS(text, lang)
  33.     --local URL = "http://translate.google.com/translate_tts?tl=" .. lang .. "&q=" .. text
  34.     local URL = "https://code.responsivevoice.org/getvoice.php?tl=" .. lang .. "&t=" .. text
  35.     -- Play the TTS. BASS returns the sound element even if it can not be played.
  36.     outputChatBox("CLIENTSIDE OK")
  37.     return true, playSound(URL), URL
  38. end
  39. addEventHandler("playTTS", root, playTTS)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top