mirror of
https://github.com/minetest-mods/MoreMesecons.git
synced 2025-01-09 17:30:24 +01:00
make it possible to let the sayers use speech dispatcher (see http://manpages.ubuntu.com/manpages/vivid/en/man1/speech-dispatcher.1.html), maybe somehow a library could be used (maybe with 'require')
This commit is contained in:
parent
e0a29b1027
commit
1af225709a
@ -1,6 +1,55 @@
|
||||
local MAX_DISTANCE = 8
|
||||
local use_speech_dispatcher = false
|
||||
|
||||
local function sayer_activate(pos)
|
||||
local sayer_activate
|
||||
if use_speech_dispatcher
|
||||
and minetest.is_singleplayer() -- must! executing commands with it and crashes may be possible
|
||||
and io.popen("if hash spd-say 2>/dev/null; then printf yes; fi"):read("*all") == "yes" then
|
||||
minetest.log("info", "[moremesecons_sayer] using speech dispatcher")
|
||||
local tab = {
|
||||
"spd-say",
|
||||
nil,
|
||||
""
|
||||
}
|
||||
local language = minetest.setting_get("language") or "en"
|
||||
if language ~= "en" then
|
||||
tab[3] = "-l "..language
|
||||
end
|
||||
MAX_DISTANCE = MAX_DISTANCE^2
|
||||
function sayer_activate(pos)
|
||||
local text = minetest.get_meta(pos):get_string("text")
|
||||
if text == "" then
|
||||
-- nothing to say
|
||||
return
|
||||
end
|
||||
if string.find(text, '"') then
|
||||
text = "So, singleplayer, you want to use me to execute commands? Writing quotes is not allowed!"
|
||||
end
|
||||
tab[2] = '"'..text..'"'
|
||||
local ppos = minetest.get_player_by_name("singleplayer"):getpos()
|
||||
ppos.y = ppos.y+1.625 -- camera position (without bobbing)
|
||||
-- that here's just 1 volume means that it's mono
|
||||
local volume = math.floor(-100*(
|
||||
1-MAX_DISTANCE/vector.distance(pos, ppos)^2
|
||||
+0.5))
|
||||
if volume <= -100 then
|
||||
-- nothing to hear
|
||||
return
|
||||
end
|
||||
if volume > 0 then
|
||||
--volume = "+"..math.min(100, volume)
|
||||
-- volume bigger 0 somehow isn't louder, it rather tries to scream
|
||||
volume = "+"..math.min(100, math.floor(volume/(MAX_DISTANCE-1)+0.5))
|
||||
end
|
||||
if volume == 0 then
|
||||
tab[4] = nil
|
||||
else
|
||||
tab[4] = "-i "..volume
|
||||
end
|
||||
os.execute(table.concat(tab, " "))
|
||||
end
|
||||
else
|
||||
function sayer_activate(pos)
|
||||
local tab = {
|
||||
"Sayer at pos",
|
||||
nil,
|
||||
@ -13,6 +62,7 @@ local function sayer_activate(pos)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_node("moremesecons_sayer:sayer", {
|
||||
description = "sayer",
|
||||
|
Loading…
Reference in New Issue
Block a user