You are not logged in.

#1 2025-10-03 21:19:53

TySpicer
Member
Registered: 2025-08-31
Posts: 109

Play sound - Override previous sound?

I'm experimenting with desktop sounds in Hyprland. Turns out, this isn't built in, but is pretty easy to set up. I have a bash script that runs commands on Hyprland events. The commands resemble this:

paplay /path/to/audio/file.wav

I'm designing my own sounds as well, which is fun! I just have one issue: if multiple sounds play back-to-back, the next sound will wait for the previous sound to finish. For example, if I open three terminal windows in quick succession, it will play my window-open sound back-to-back three times, but since each one takes longer than it takes to open the windows, they're out of sync with the actual windows opening. I've tested this in a simple terminal window, and it has the same behavior.

I suppose I could make the sounds shorter, but that could interfere with the aesthetic. I've tried to trim the files so that there's no extra space at the beginning and end, but this only goes so far.

Is there a way to get a sound to override the previous sound with `paplay`? Is there another tool that could accomplish this?

Offline

#2 2025-10-07 07:43:51

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 24,778

Re: Play sound - Override previous sound?

where are you adding those playback commands exactly, which files? Chances are you are blocking further execution of shell startup because you are waiting for the paplay commands to end. You can consider either killing existing paplay instances before invoking another or background the execution of the paplay commands so that they can overlap. e.g.

killall paplay; paplay ...

and/or

paplay ... &

maybe even combine the two.

If it's explicitly about event sounds, stuff like https://wiki.archlinux.org/title/Libcanberra is more targeted to this and it also has a standalone playback utility that maintains a sample cache, might want to give that a shot.

Offline

#3 2025-10-07 21:07:40

TySpicer
Member
Registered: 2025-08-31
Posts: 109

Re: Play sound - Override previous sound?

V1del wrote:

where are you adding those playback commands exactly, which files?

`~/.config/hypr/Scripts`:

#!/bin/sh

handle() {
  case $1 in
    openwindow*)			paplay ~/Documents/Sounds/Ty/soft-click-up-2025-10-03.wav ;;
    closewindow*)			paplay ~/Documents/Sounds/Ty/soft-click-down-2025-10-03.wav ;;
    changefloatingmode*)		paplay ~/Documents/Sounds/Ty/tiny-click-2025-10-03.wav ;;
    fullscreen*)			paplay ~/Documents/Sounds/Ty/soft-click-short-2025-10-03.wav ;;
  esac
}

socat -U - UNIX-CONNECT:$XDG_RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock | while read -r line; do handle "$line"; done

Then I have the following line in `~/.config/hypr/hyprland.conf`:

exec-once = exec sh ~/.config/hypr/Scripts/animation-sounds.sh
V1del wrote:

If it's explicitly about event sounds

I'm not sure if this is what I'm looking for. I'm using IPC: https://wiki.hypr.land/IPC/

I don't know much about it, but as far as I can tell, this has to do with events specifically in Hyprland. Is this related to Libcanberra, or is it separate? I could look into Libcanberra eventually, I'm taking a break from Arch stuff for a few days (except for checking what I already posted).

I tried altering `animation-sounds.sh` a bit based on your suggestions. The following didn't seem to have any effect:

killall paplay; paplay ...
paplay ... && killall paplay

The following resulted in there just being no sound:

killall paplay && paplay ...
V1del wrote:

so that they can overlap

I actually wouldn't mind this, depending on how messy it ends up sounding. I'm not sure how I would implement that in this file, though.

Offline

Board footer

Powered by FluxBB