0

I was trying to customize my org-clock-sound with a file I took from Wikimedia Commons (here is the file). I know that Emacs can only play, natively, .wav and .au files. But apparently, my file is recognized as an "x-wav" file, as I see from my file manager: "Type: WAV audio (audio/x-wav)". When I inspect it with file, I get:

Bicycle-bell-1.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 24 bit, stereo 44100 Hz

Unsurprisingly, when I try to set the variable:

(setq org-clock-sound "/home/alessandro/.emacs.d/Bicycle-bell-1.wav")

and the bell is triggered, I get the standard "bip", as if org-clock-sound was set to t.

So, it seems Emacs cannot recognize it.

I have found a workaround solution: I tried using an online converter to produce an .au file, and it works!. Inspecting with the file manager gives "Type: ULAW (Sun) audio (audio/basic)", and with file:

Bicycle-bell-1.au: Sun/NeXT audio data: 16-bit linear PCM, stereo, 44100 Hz

However, I've already written this question, so for the sake of bug-solving, my questions are:

  1. Can I play the x-wav file on Emacs?
  2. Is there a way I can convert it in .wav? Is the mailcap.el library useful in some way?

Thanks for your time!


Some additional information that may be useful:

  • Calling the function (play-sound "~/.emacs.d/Bicycle-bell-1.wav") gives the error
Debugger entered--Lisp error: (error "Invalid sound specification")
  play-sound-internal("~/.emacs.d/Bicycle-bell-1.wav")
  play-sound("~/.emacs.d/Bicycle-bell-1.wav")
  (progn (play-sound "~/.emacs.d/Bicycle-bell-1.wav"))
  eval((progn (play-sound "~/.emacs.d/Bicycle-bell-1.wav")) t)
  • Calling the function (play-sound-file "~/.emacs.d/Bicycle-bell-1.wav") gives the error
Debugger entered--Lisp error: (error "Unsupported WAV file format")
  play-sound-internal((sound :file "~/.emacs.d/Bicycle-bell-1.wav"))
  play-sound((sound :file "~/.emacs.d/Bicycle-bell-1.wav"))
  play-sound-file("~/.emacs.d/Bicycle-bell-1.wav")
  (progn (play-sound-file "~/.emacs.d/Bicycle-bell-1.wav"))
1
  • The Bicycle-bell-1.wav file is 24-bit and even if your emacs is built with the alsa libraries, they don't seem able to play 24-bit WAV files. You can convert it to 16-bit with ffmpeg and try again. See the edit in my answer.
    – NickD
    Commented Feb 12, 2022 at 15:56

1 Answer 1

1

Assuming you are on Linux and you are using ALSA, org-notify calls org-clock-play-sound to (optionally) play a sound. org-clock-play-sound uses the aplay program (part of the alsa-utils package) to play the sound. So from the command line, try aplay /path/to/Bicycle-bell-1.wav. If that works, be happy with (org-clock-play-sound "/path/to/Bicycle-bell-1.wav").

play-sound-file and its subordinates, play-sound and play-sound-internal, only come in if the above does NOT work. You use it like this:

`(play-sound-file "/path/to/Bicycle-bell-1.wav" 80 "some_device")`

where "some_device" is a string that specifies an ALSA output device. The last two arguments are optional, but at least in my case, without them I get the error:

(error "No usable sound device driver found")

That comes from deep in play-sound-internal which is a C function in the file src/sound.c. I have no idea what device to use to make it behave however.

The subordinates require a different calling convention. Do C-h f play-sound to read about it. The call to play-sound should look like this:

(play-sound '(sound :file "/path/to/Bicycle-bell-1.wav" :volume 80 :device "some_device")

but here again, I have no idea what "some_device" should be to make it behave. I guess it should be an ALSA device and (maybe) you can use aplay -l to find out its name, but this is beyond my comfort zone.

In short, if you are on Linux and using ALSA (the latter is almost a certain consequence of the former), then try installing the alsa-utils package (whatever it is called in your distro) and check that the aplay program is installed. That's the shortest way to bliss.

Otherwise, you will have to do some digging to find an ALSA device that Emacs can initialize and use, and somehow make it the default device so that it can be used from org-clock-play-sound without arguments.

If you are NOT on Linux, the low level ALSA comments above have to be replaced by even more vague comments about the sound system on your platform: I know zilch about them so I'm not going to even try to go there.

EDIT: the file Bicycle-bell-1.wav is a 24-bit WAV file. Try converting it to 16-bit and check with mediainfo to make sure it is 16-bit:

$ ffmpeg -i Bicycle-bell-1.wav foo.wav
$ mediainfo foo.wav
...
Bit depth                                : 16 bits
...

Also check whether your Emacs has been built with ALSA support:

ldd $(which emacs) | grep sound
    libasound.so.2 => /lib64/libasound.so.2 (0x00007fce0efec000)

If the output is empty, complain to your distro and ask them to build Emacs with ALSA support. Or if you are building your own, install alsa-lib-devel (that's the Fedora name: YMMV depending on your distro) and rebuild emacs.

2
  • 1
    Hi, thanks for your answer. I have the package pipewire-alsa installed, not alsa directly. So I don't have right now programs like aplay or mediainfo. However, checking the linked library of Emacs, it uses libasound.so.2. Converting the file with ffmpeg and setting to it org-clock-sound does not raise an error, but the file is not played (only a "TOC" is hearable). I noticed I was using function play-sound incorrectly. Trying with the correct syntax gives the same results as before (good with .au, error with 24 bit x-wav, deep tick with 16 bit) Commented Feb 13, 2022 at 9:14
  • Yes, you are right. That's what I get too. You should go ahead and install alsa-utils which will give you aplay. I think that's the easiest way to resolve the problem (and aplay can play 24-bit files).
    – NickD
    Commented Feb 13, 2022 at 13:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.