Files
2025-07-18 19:23:56 -04:00

53 lines
1.6 KiB
Lua

local mp = require 'mp'
local utils = require 'mp.utils'
local originalVolume = 100
-- Fade volume from current to target in steps
local function fade_volume(target, steps, interval, callback)
local current = tonumber(mp.get_property("volume"))
local delta = (target - current) / steps
local i = 0
local function step()
i = i + 1
local newVolume = current + delta * i
mp.set_property("volume", tostring(newVolume))
if i < steps then
mp.add_timeout(interval, step)
elseif callback then
callback()
end
end
step()
end
function speak_metadata()
originalVolume = tonumber(mp.get_property("volume")) or 100
local targetVolume = math.max(originalVolume * 0.3, 1)
-- Get message using playerctl
local result = utils.subprocess({
args = {"playerctl", "metadata", "-f", "{{artist}} - {{album}} - {{title}}"}
})
local msg
if result.status == 0 and result.stdout and result.stdout:match("%S") then
msg = result.stdout:gsub("\n", "")
else
local fallback = mp.get_property("media-title") or mp.get_property("filename/no-ext") or "unknown file"
msg = "Now playing: " .. fallback
end
-- Fade down, speak via RHVoice, then fade up
fade_volume(targetVolume, 10, 0.05, function()
utils.subprocess({
args = {"bash", "-c", string.format("echo %q | RHVoice-test -v 500 --", msg)}
})
fade_volume(originalVolume, 10, 0.05)
end)
end
mp.add_key_binding("F1", "speak_metadata", speak_metadata)