This commit is contained in:
2026-05-05 17:41:22 -04:00
parent 57f83bd56b
commit 875edb891a
4 changed files with 254 additions and 13 deletions

View File

@@ -1,15 +1,11 @@
local speaker = peripheral.find("speaker")
local dfpwm = require("cc.audio.dfpwm")
local encoder = dfpwm.make_encoder()
local decoder = dfpwm.make_decoder()
local sounds = {
{name = "notification", file = "notification.dfpwm"}
}
local function initialize()
kernel = require("kernel")
kernel.addSound("notification")
speaker = peripheral.find("speaker")
if not speaker then
print("Warning: No speaker attached.")
@@ -39,7 +35,6 @@ local function play(name)
return false
end
-- Create a new decoder for this playback to reset state
local decoder = dfpwm.make_decoder()
for chunk in io.lines(filePath, 16 * 1024) do
@@ -50,7 +45,6 @@ local function play(name)
end
return true
end
----------------
local function getFileName(name)
local extension = ".dfpwm"
@@ -68,6 +62,7 @@ end
local function playSound(fileName)
local fileStream = getFileName(fileName)
local decoder = dfpwm.make_decoder()
local values = io.lines(fileStream, 16 * 1024)
for input in values do
local decoded = decoder(input)
@@ -77,20 +72,26 @@ local function playSound(fileName)
end
end
local function playTTSFile(value)
local message = textutils.urlEncode(value)
local url = "http://api.astrocore.space/api/TextToSpeech?message=" .. message
local response, err = http.get { url = url, binary = true }
if not response then
print("TTS request failed: " .. (err or "unknown error"))
return false
end
local name = randomFileName()
local fileName = name .. ".dfpwm"
local fileData = response.readAll()
local file = fs.open(fileName,"w")
response.close()
local file = fs.open(fileName, "wb")
file.write(fileData)
file.close()
response.close()
playSound(name)
shell.execute("rm", fileName)
end