This commit is contained in:
2025-06-16 19:37:02 -04:00
parent 696f7106a4
commit 61724d2df6

View File

@@ -9,6 +9,13 @@ local function getFileName(name)
return fullFile return fullFile
end end
local function randomFileName(extension)
local name = ""
for i = 1, 12 do
name = name .. string.char(math.random(97, 122)) -- az
end
return name .. (extension or "")
end
local function playSound(speaker, fileName) local function playSound(speaker, fileName)
local fileStream = getFileName(fileName) local fileStream = getFileName(fileName)
@@ -38,16 +45,14 @@ local function playTTSFile(speakers, value)
local message = textutils.urlEncode(value) local message = textutils.urlEncode(value)
local url = "http://api.astrocore.space/api/TextToSpeech?message=" .. message local url = "http://api.astrocore.space/api/TextToSpeech?message=" .. message
local response, err = http.get { url = url, binary = true } local response, err = http.get { url = url, binary = true }
if not response then error(err, 0) end local name = randomFileName(".dfpwm")
while true do local fileData = response.readAll()
local chunk = response.read(16 * 1024) local file = fs.open(name,"w")
if not chunk then break end file.write(fileData)
file.close()
local buffer = decoder(chunk) response.close()
while not speakers.playAudio(buffer, 200) do playSound(speakers, fileData)
os.pullEvent("speaker_audio_empty") shell.execute("rm", name)
end
end
end end
local function createSoundFile(fileName) local function createSoundFile(fileName)