Getting X11 XBell event to play through PulseAudio

Asked by Mike Mol

To reproduce the problem I'm having:

1) Launch 'xterm'
2) Run: echo -e "\a"

What you _should_ hear is some kind of notification sound. echo -e "\a" produces a terminal bell, xterm translates that to an XBell event, and pulseaudio's module-x11-bell should hook into that, receive the event, and play the sample it's configured to play. (By default, that looks like "bell.ogg").

What I hear: Nothing.

Running pavucontrol doesn't indicate any problem with my hardware. I can browse to sound-emitting websites and hear them just fine in browsers such as Chromium.

Environment: I don't use a full desktop environment such as KDE, GNOME or XFCE which will set up PulseAudio integration for me. Instead, I use 'awesome', as it's what I'm most productive with. I do use gdm, or sometimes slim, as my session manager.

I am running "start-pulseaudio-x11" immediately upon login.

I'm running Ubuntu Precise, as it's the same platform for which I'm doing active target development. Updating to Ocelot is not an option at this moment.

Question information

Language:
English Edit question
Status:
Expired
For:
Ubuntu xorg Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
actionparsnip (andrew-woodhead666) said :
#1

Do you get normal sounds in sound apps?

Revision history for this message
Mike Mol (mikemol) said :
#2

Yes. I can use Chromium to browse to Youtube, Pandora, etc. Skype functions. Google Talk makes alert noises at me.

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#3

Is the level muted / low for the bell in sound options under dash?

Revision history for this message
Mike Mol (mikemol) said :
#4

No, sound is not muted, at least not according to pavucontrol. Again, I'm not running GNOME, Unity, KDE, LXDE or XFCE.

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#5

What DE / WM etc are you using?

Revision history for this message
Mike Mol (mikemol) said :
#6

I am using the WM named 'awesome'. I am not using a full DE. I use GDM or slim as a session manager.

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#7

Gotcha. Have you tried:

sudo modprobe pcspkr

Then trying the beep?

Revision history for this message
Mike Mol (mikemol) said :
#8

Does not work. Again, the goal is to have PulseAudio catch the XBell X11 event, and play a sound in response. According to "pactl list", the sample currently configured is "bell.ogg".

The goal is not to have sound come out the PC speaker.

Revision history for this message
Launchpad Janitor (janitor) said :
#9

This question was expired because it remained in the 'Open' state without activity for the last 15 days.

Revision history for this message
sdaau (sd-imi) said :
#10

I'm not sure if this is really PulseAudio specific, but I had the same problem - trying out awesome-wm in Ubuntu 11.04, and not having any audio bell notification feedback upon `echo -e "\a"` or Ctrl-G in `gnome-terminal`.

The key to this problem is in:

[https://bugzilla.redhat.com/show_bug.cgi?id=607393 Bug 607393 – XBell doesn't work at all]

especially Comment 22:

> PA doesn't do any xkb bell magic by default. That's intended. If you want to hookup xkb bell with
> proper audio then use a window manager that is able to forward xkb bell events to libcanberra
> or suchlike, the way metacity does it.

The biggest problem for me was to see how to track down if an audio bell event is generated at all - `xev` doesn't report it. After finding this:

[http://wiesmann.codiferes.net/wordpress/?p=4536&lang=en Thias の blog » Blog Archive » xkbbell & xkbevd]

... I learned that `xkbevd` is the program that reports these events; e.g.:

$ xkbevd
Temporarily disabling the audible bell

XkbControlsNotify event, serial 9, synthetic no, device 3, time 7257451,
    changed= 0x80000000, enabled= 0x1181, enabledChanges= 0x200
    num_groups= 3
    request -111/7 (NON-XKB)

XkbBellNotify event, serial 12, synthetic no, device 3, time 7257453,
    bell class= 0, id= 0
    percent= 0, pitch= 400, duration= 100
    name= "ImAlive"
    window= 0x0, event_only

XkbStateNotify event, serial 13, synthetic no, device 3, time 7260208,
    keycode 1, eventType unknown,
    group= 0, base= 0, latched= 0, locked= 0,
    mods= 0x00, base= 0x00, latched= 0x00, locked= 0x00
    grab mods= 0x00, compat grab mods= 0x00
    lookup mods= 0x00, compat lookup mods= 0x00
    compatState = 0x00, ptr_buttons= 0x0100*
....
# upon trigerring audio bell in terminal:

 XkbBellNotify event, serial 13, synthetic no, device 3, time 7277053,
    bell class= 0, id= 0
    percent= 0, pitch= 400, duration= 100, no name
    window= 0x0, !event_only
...

So, I though - I could simply grep this output, and trigger a sound playback somehow. The problem, though, is that `xkbevd` terminal output seems to disappear if it is piped to say, `cat`; though that can be solved by "line-buffering" its output with:

stdbuf -oL xkbevd | cat

Nevermind that, even better is that `man xkbevd` says:

       The xkbevd event daemon listens for specified XKB events and executes
       requested commands if they occur. The configuration file consists of
       a list of event specification/action pairs and/or variable definitions. ...
       The interpretation of the qualifier depends on the
       type of the event: Bell events match using the name of the bell, ...
       An action consists of an optional keyword followed by an optional
       string argument. Currently, xkbev recognizes the actions: none,
       ignore, echo, printEvent, sound, and shell. ...

There is no default configuration file installed for xkbevd on Ubuntu, but there is

cp /usr/share/doc/x11-xkb-utils/xkbevd-example.cf ~/xkbevd-example.cf

Eventually, I ended up deleting most of the file copied in home directory, and now just have:

====
$ cat ~/xkbevd-example.cf
soundDirectory = "/usr/share/sounds/ubuntu/stereo/"

Bell() "bell.ogg &"
====

Note the ampersand `&`at the end of the filename - this is to "cheat" the xbkvd interpreter, so it starts audio player as a process, so it can exit immediately - otherwise, it most audio players I've tried will lock for about second or two after they're done playing (see also

http://unix.stackexchange.com/questions/75421/command-line-audio-player-that-exits-immediately-after-file-finished-playing-bac
)

, which will also block `xkbevd`, which means not all events that should play an audio bell will do so.

Finally, to test, do in one terminal:

xkbevd -cfg ~/xkbevd-example.cf -sc "canberra-gtk-play -f"

... and in another terminal, trigger audio bell (with arrow keys, or Ctrl-g, or with echo, etc); now xkbevd should both show messages, and the bell sound should be played... (apparently, what is done here by `xkbevd` listening to bell event, and trigerring playback is what is done by `metacity` in gnome 2).

Now if this works, you'd want to start it up when the awesome-wm session starts; I believe adding:

awful.util.spawn('xkbevd -cfg ~/xkbevd-example.cf -sc "canberra-gtk-play -f"')

... at end of rc.lua would do it: maybe an ampersand (to start as process) will be necessarry at end of command, maybe not (haven't tried it yet) - but I think this `xkbevd` in general should solve the issue.

Hope this helps someone,
Cheers!

Revision history for this message
Mike Mol (mikemol) said :
#11

Hah!

I just finished ripping out PulseAudio from my Gentoo setup on my laptop two weeks ago...and had all but resigned myself to writing a daemon that listens for bell event and plays a sound. Your comment here comes with nigh-perfect timing...

Anyway, for those who come across this trying to get it working with PulseAudio, here's what works for me:

pactl upload-sample /usr/share/sounds/freedesktop/stereo/bell.oga bell.ogg
pactl load-module module-x11-bell sample=bell.ogg

I place that in a shell script I run on login. (I've never been successful at getting personalized rc.lua scripts running; I always wind up borking my login session somehow.)