Module: lib-tde.volume
This module exposes an api to manipulate volume events through pulseaudio/pipewire
Useful functional for setting volume active sinks, input/output etc
Info:
- Copyright: 2020 Tom Meyers
- Author: Tom Meyers
Static module functions
lib-tde.volume.get_volume (callback) | Get the volume asynchronously | |
lib-tde.volume.inc_volume () | Increase the current volume level by 5% | |
lib-tde.volume.dec_volume () | Decrease the current volume level by 5% | |
lib-tde.volume.toggle_master () | Toggle the current volume state between muted and unmuted on the master channel | |
lib-tde.volume.set_muted_state (bIsMuted) | Set the muted state | |
lib-tde.volume.get_application_volume (sink, callback) | Get the volume of an application asynchronously | |
lib-tde.volume.set_volume (sink, value) | Set the volume of an application in percentage | |
lib-tde.volume.set_volume (value) | Set the volume in percentage | |
lib-tde.volume.get_sinks () | Get a list of all audio sinks back (A sink is an audio player such as headphones, speakers or monitors) | |
lib-tde.volume.get_applications () | Get a list of all applications that are currently playing audio | |
lib-tde.volume.set_default_sink (sink) | Change the default sink (change the audio playback device) | |
lib-tde.volume.get_default_sink () -> () | Return only the default sink | |
lib-tde.volume.get_sources () | Get a list of all audio sources back (A source is an audio recording device such as microphones) | |
lib-tde.volume.set_default_source (source) | Change the default source (change the audio playback device) | |
lib-tde.volume.get_default_source () -> () | Return only the default source | |
lib-tde.volume.reset_server () | Resets the active audio server (either pulseaudio or pipewire) |
Object properties
name | string | The canonical name of the audio device | |
sink | number | the current sink/source number (used to set sink/source) | |
port | string | The active port in the sink/source | |
id | string | The unique identifier for the sink |
Static module functions
- lib-tde.volume.get_volume (callback)
-
Get the volume asynchronously
Parameters:
- callback function A callback function to trigger when the volume is gathered
Usage:
-- Get the volume in percentage get_volume(function(percentage, muted) print("Current volume level: " .. tostring(percentage)) end)
- lib-tde.volume.inc_volume ()
-
Increase the current volume level by 5%
Usage:
-- Increase the current volume level inc_volume()
- lib-tde.volume.dec_volume ()
-
Decrease the current volume level by 5%
Usage:
-- Decrease the current volume level dec_volume()
- lib-tde.volume.toggle_master ()
-
Toggle the current volume state between muted and unmuted on the master channel
Usage:
-- Toggle the muted state toggle_master()
- lib-tde.volume.set_muted_state (bIsMuted)
-
Set the muted state
Parameters:
- bIsMuted boolean The state that we need to set (true if we need to mute the output)
Usage:
-- Set the master channel to mute set_muted_state(true)
- lib-tde.volume.get_application_volume (sink, callback)
-
Get the volume of an application asynchronously
Parameters:
- sink number The sink property of the application
- callback function A callback function to trigger when the volume data is gathered
Usage:
-- Get the volume of sink number 10 get_application_volume(10,function(percentage, muted) print("Current volume level of application" .. sink.name ..": " .. tostring(percentage)) end)
- lib-tde.volume.set_volume (sink, value)
-
Set the volume of an application in percentage
Parameters:
- sink number The sink of a given application
- value number The value of the volume in percentage
Usage:
-- Set the volume to max (of application with sink #75) set_volume(75, 100)
- lib-tde.volume.set_volume (value)
-
Set the volume in percentage
Parameters:
- value number The value of the volume in percentage
Usage:
-- Set the volume to max set_volume(100)
- lib-tde.volume.get_sinks ()
-
Get a list of all audio sinks back (A sink is an audio player such as headphones, speakers or monitors)
Usage:
-- Returns an iterable table containing all sinks get_sinks() -- returns a list of sinks
- lib-tde.volume.get_applications ()
-
Get a list of all applications that are currently playing audio
Usage:
-- Returns an iterable table containing all applications playing audio get_applications() -- returns a list of application
- lib-tde.volume.set_default_sink (sink)
-
Change the default sink (change the audio playback device)
Parameters:
- sink number The sink property of our audio device
Usage:
-- Set our default sync to match the first device set_default_sink(get_sinks()[1].sink)
- lib-tde.volume.get_default_sink () -> ()
-
Return only the default sink
Returns:
-
table sink The currently active sink
Usage:
-- Get the default sink (the currently active audio device) local sink = get_default_sink()
- lib-tde.volume.get_sources ()
-
Get a list of all audio sources back (A source is an audio recording device such as microphones)
Usage:
-- Returns an iterable table containing all sources get_sources() -- returns a list of sources
- lib-tde.volume.set_default_source (source)
-
Change the default source (change the audio playback device)
Parameters:
- source number The sink property of our audio device
Usage:
-- Set our default source to match the first device set_default_source(get_sources()[1].sink)
- lib-tde.volume.get_default_source () -> ()
-
Return only the default source
Returns:
-
table source The currently active source
Usage:
-- Get the default sink (the currently active microphone) local source = get_default_source()
- lib-tde.volume.reset_server ()
-
Resets the active audio server (either pulseaudio or pipewire)
Usage:
-- Reset the entire audio server (temporarily breaks audio) reset_server()