Compare commits

...

10 Commits

Author SHA1 Message Date
2711d658ea updated a bunch 2025-06-17 17:09:57 -04:00
4e57946e82 fix: update TTS playback for speaker initialization 2025-06-16 20:52:18 -04:00
8cf446d391 d 2025-06-16 20:50:37 -04:00
110ceed23d fix: replace peripheral.wrap with peripheral.find for speaker initialization 2025-06-16 20:49:03 -04:00
7839936ea7 da 2025-06-16 20:47:06 -04:00
7dc79632ca updated 2025-06-16 20:45:43 -04:00
685c24a44a updated 2025-06-16 20:43:41 -04:00
65934b61ce updated 2025-06-16 20:40:57 -04:00
8f64d54c00 fix: simplify playSingleSound function by removing unnecessary loop 2025-06-16 20:37:06 -04:00
b428c24a1f updated 2025-06-16 20:36:04 -04:00
4 changed files with 38 additions and 56 deletions

View File

@@ -4,21 +4,6 @@ local modem = peripheral.find("modem")
local monitor = peripheral.wrap("top") local monitor = peripheral.wrap("top")
controlRoomSpeakers = peripheral.find("speaker") controlRoomSpeakers = peripheral.find("speaker")
local speakers = {
peripheral.wrap("speaker_0"),
peripheral.wrap("speaker_1"),
peripheral.wrap("speaker_2"),
peripheral.wrap("speaker_3"),
peripheral.wrap("speaker_4"),
peripheral.wrap("speaker_5"),
peripheral.wrap("speaker_6"),
peripheral.wrap("speaker_7"),
peripheral.wrap("speaker_8"),
peripheral.wrap("speaker_9"),
peripheral.wrap("speaker_10"),
peripheral.wrap("speaker_11"),
}
function setNewLine() function setNewLine()
local x,y = monitor.getCursorPos() local x,y = monitor.getCursorPos()
monitor.setCursorPos(1, y + 1) monitor.setCursorPos(1, y + 1)
@@ -27,11 +12,8 @@ end
local function startup() local function startup()
speakerDriver.startup() speakerDriver.startup()
--speakerDriver.playControlRoomAlarm(controlRoomSpeakers) speakerDriver.playTTSFile(peripheral.wrap("left"), "ELLO MATE LOVELY DAY INIT YOU GOT ANYYYY BEEEANSS AND TOAST ON YA MATE ID LOVE TO HAVE SOME BEANS N TOAST")
--speakerDriver.playExternalAlarm(controlRoomSpeakers) speakerDriver.playTTSFile(peripheral.wrap("right"), "ELLO MATE LOVELY DAY INIT YOU GOT ANYYYY BEEEANSS AND TOAST ON YA MATE ID LOVE TO HAVE SOME BEANS N TOAST")
--speakerDriver.playInternalAlarm(controlRoomSpeakers)
speakerDriver.playTTSFile(speakers, "ELLO MATE LOVELY DAY INIT YOU GOT ANYYYY BEEEANSS AND TOAST ON YA MATE ID LOVE TO HAVE SOME BEANS N TOAST")
speakerDriver.playTTSFile(speakers, "ITS ME NOVA ELLO THEY GOT ME LOCKED IN A BLOOOODY BOX MATE")
end end
local function run() local function run()

View File

@@ -17,44 +17,17 @@ local function randomFileName()
return name return name
end end
local function playSound(speaker, fileName)
local function playSingleSound(speaker, values) local fileStream = getFileName(fileName)
local values = io.lines(fileStream, 16 * 1024)
for input in values do for input in values do
print("playing audo....") print("playing audo....")
local decoded = decoder(input) local decoded = decoder(input)
speaker.playAudio(decoded, 3) while not speaker.playAudio(decoded, 3) do
os.pullEvent("speaker_audio_empty")
end end
end end
local function playSound(speaker, fileName)
local fileStream = fs.ope(getFileName(fileName), "r")
local data = fileName.readAll()
local speakers = table.pack(peripheral.find("speaker"))
local tasks = {}
for i = 1, speakers.n do
tasks[i] = function()
playSingleSound(speakers[i], data)
end end
end
parallel.waitForAll(table.unpack(tasks, 1, speakers.n))
end
-- local function playSound(speaker, fileName)
-- local fileStream = getFileName(fileName)
-- local values = io.lines(fileStream, 16 * 1024)
-- for input in values do
-- print("playing audo....")
-- local decoded = decoder(input)
-- while not speaker.playAudio(decoded, 3) do
-- os.pullEvent("speaker_audio_empty")
-- end
-- end
-- end
local function playControlRoomAlarm(speakers) local function playControlRoomAlarm(speakers)
playSound(speakers,"short_control_alarm") playSound(speakers,"short_control_alarm")
@@ -63,6 +36,7 @@ end
local function playExternalAlarm(speakers) local function playExternalAlarm(speakers)
playSound(speakers,"external_alarm") playSound(speakers,"external_alarm")
end end
local function playInternalAlarm(speakers) local function playInternalAlarm(speakers)
playSound(speakers,"internal_alarm") playSound(speakers,"internal_alarm")
end end
@@ -111,14 +85,11 @@ local function createSoundFile(fileName)
local file = fs.open(name,"w") local file = fs.open(name,"w")
file.write(fileData) file.write(fileData)
file.close() file.close()
handle.close() handle.close()
end end
function addSoundFile(fileName) function addSoundFile(fileName)
createSoundFile(fileName) createSoundFile(fileName)
end end

25
speaker_main.lua Normal file
View File

@@ -0,0 +1,25 @@
speaker = peripheral.find("speaker")
speakerDriver = kernel.addDriver("speaker_driver")
local function startup()
parallel.waitForAll(speakerDriver.startup)
end
local function shutDown()
parallel.waitForAll(speakerDriver.shutDown)
end
local function runSafe()
startup()
end
local function run()
local success, err = pcall(runSafe)
if not success then
os.reboot()
end
end
return { run = run }

4
speaker_startup.lua Normal file
View File

@@ -0,0 +1,4 @@
local kernel = require("kernel")
local main = kernel.addDriver("speaker_main")
sleep(5)
main.run()