On 11/4/24 15:36, Weiwu Zhang wrote:
Use of Numid: After that, I tried using the numeric identifier (numid)
for the controls: amixer -c 0 cset numid=105 90%. This time, the
command failed with a different error: "amixer: control.c:427:
snd_ctl_elem_info: Assertion `ctl && info && (info->id.name[0] ||
info->id.numid)' failed. Aborted (core dumped)".
There is no way to get around the core dump issue with amixer after all,
and the workaround I found is by writing this script
$ cat set_vol_80.py
import alsaaudio
def set_volume(control_name, volume):
"""
Set the volume for a specific control name.
Args:
control_name (str): The name of the control.
volume (int): The volume level to set (range from 0 to 31).
"""
# Open the mixer for the specific card and control
mixer = alsaaudio.Mixer(control=control_name, cardindex=0,
device='SC8280XP-LENOVO-X13S')
# Set volume
mixer.setvolume(volume)
def get_volume(control_name):
"""
Get the current volume for a specific control name.
Args:
control_name (str): The name of the control.
Returns:
int: The current volume level.
"""
# Open the mixer for the specific card and control
mixer = alsaaudio.Mixer(control=control_name, cardindex=0,
device='SC8280XP-LENOVO-X13S')
# Get volume
return mixer.getvolume()[0]
# Control names for the speakers
spkr_left_name = 'SpkrLeft PA'
spkr_right_name = 'SpkrRight PA'
# Example usage: Setting volume
set_volume(spkr_left_name, 80) # Set left speaker volume to 80
set_volume(spkr_right_name, 80) # Set right speaker volume to 80
# Example usage: Getting current volume
left_volume = get_volume(spkr_left_name)
right_volume = get_volume(spkr_right_name)
print("Current Left Speaker Volume:", left_volume)
print("Current Right Speaker Volume:", right_volume)
_______________________________________________
Alsa-user mailing list
Alsa-user@xxxxxxxxxxxxxxxxxxxxx
https://lists.sourceforge.net/lists/listinfo/alsa-user