say in own library

This commit is contained in:
tangent committed 2026-09-22 21:19:18 -06:00
1 parent e40ffb91da
commit d176ef90f8
2 files changed
+39 -31

No files matched your search

+36
View File
@@ -0,0 +1,36 @@
local log = require "lib.log"
local utility = require "lib.utility"
local voices = utility.load_data("macos_say-en.json")
local say_thread = love.thread.newThread([[
local channel = love.thread.getChannel("say")
while true do
local message = channel:demand()
if message then
os.execute("say -v " .. message.voice .. " " .. message.line)
end
end
]])
say_thread:start()
return setmetatable({
update = function()
local thread_error = say_thread:getError()
if thread_error then
log("error", thread_error)
end
end,
}, {
__call = function(self, line)
local selected_voice = voices[math.random(1, #voices)]
local say_channel = love.thread.getChannel("say")
line = line or "Hello, my name is " .. selected_voice .. "."
say_channel:push({
voice = selected_voice:enquote(),
line = line:enquote(),
})
log("say", selected_voice, line)
end,
})