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

60 lines
1.7 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 to speak text using RHVoice with volume fading
local function speak_text(text)
originalVolume = tonumber(mp.get_property("volume")) or 100
local targetVolume = math.max(originalVolume * 0.3, 1)
-- 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 --", text)}
})
fade_volume(originalVolume, 10, 0.05)
end)
end
-- Toggle shuffle mode and announce it with voice feedback
function toggle_shuffle()
local current_shuffle = mp.get_property_native("shuffle")
local new_shuffle = not current_shuffle
mp.set_property_native("shuffle", new_shuffle)
local status_message
if new_shuffle then
status_message = "Random playback on"
else
status_message = "Sequential playback"
end
-- Speak the status using the same strings as in music_player.py
speak_text(status_message)
end
-- Bind key for the toggle shuffle function
mp.add_key_binding("r", "toggle_shuffle", toggle_shuffle)