CelticCoder

tts-template

May 6th, 2024
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.56 KB | None | 0 0
  1. local message = "Just fiddling with text to speech."
  2.  
  3. local url = "https://music.madefor.cc/tts?text=" .. textutils.urlEncode(message)
  4. local response, err = http.get { url = url, binary = true }
  5. if not response then error(err, 0) end
  6.  
  7. local speaker = peripheral.find("speaker")
  8. local decoder = require("cc.audio.dfpwm").make_decoder()
  9.  
  10. while true do
  11.     local chunk = response.read(16 * 1024)
  12.     if not chunk then break end
  13.  
  14.     local buffer = decoder(chunk)
  15.     while not speaker.playAudio(buffer) do
  16.         os.pullEvent("speaker_audio_empty")
  17.     end
  18. end
Add Comment
Please, Sign In to add comment