Mpv customization scripts added.
This commit is contained in:
52
home/stormux/.config/mpv/scripts/speak-meta.lua
Normal file
52
home/stormux/.config/mpv/scripts/speak-meta.lua
Normal file
@@ -0,0 +1,52 @@
|
||||
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)
|
||||
59
home/stormux/.config/mpv/scripts/toggle-shuffle.lua
Normal file
59
home/stormux/.config/mpv/scripts/toggle-shuffle.lua
Normal file
@@ -0,0 +1,59 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user