say in own library
This commit is contained in:
@@ -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,
|
||||
})
|
||||
+3
-31
@@ -2,6 +2,7 @@ local window_width, window_height = love.graphics.getDimensions()
|
||||
|
||||
local log = require "lib.log"
|
||||
local lovebird = require "lib.lovebird"
|
||||
local macOS_say = require "lib.macOS_say"
|
||||
local progress_bar = require "lib.progress_bar"
|
||||
local timer = require "lib.timer"
|
||||
local utility = require "lib.utility"
|
||||
@@ -18,31 +19,6 @@ local constants = require "data.constants"
|
||||
local classes = require "data.classes"
|
||||
local races = require "data.races"
|
||||
|
||||
local voices = utility.load_data("macos_say-en.json")
|
||||
local macOS_say = function(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
|
||||
-- macOS_say()
|
||||
|
||||
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()
|
||||
|
||||
local new_character = function(name)
|
||||
local base_stat_roll = function()
|
||||
return 3 + math.random(1, 6) + math.random(1, 6) + math.random(1, 6)
|
||||
@@ -67,7 +43,7 @@ local new_character = function(name)
|
||||
|
||||
name = name or random_name(math.random(3, 9)) -- name not affected by seed
|
||||
|
||||
local seed = os.time()
|
||||
local seed = math.random()
|
||||
math.randomseed(seed)
|
||||
|
||||
local character = {
|
||||
@@ -87,7 +63,6 @@ local new_character = function(name)
|
||||
character.health = math.random(1, 8) + math.floor(character.constitution / 6)
|
||||
character.magic = math.random(1, 8) + math.floor(character.intelligence / 6)
|
||||
|
||||
math.randomseed(os.time())
|
||||
return character
|
||||
end
|
||||
|
||||
@@ -131,10 +106,7 @@ love.update = function(dt)
|
||||
|
||||
test_bar:set_progress(test_timer.run_time / test_timer:get_interval())
|
||||
|
||||
local thread_error = say_thread:getError()
|
||||
if thread_error then
|
||||
log("error", thread_error)
|
||||
end
|
||||
macOS_say:update()
|
||||
end
|
||||
|
||||
love.draw = function()
|
||||
|
||||
Reference in New Issue
Block a user