org-pomodoro 无法发出声音

系统是Arch,想使用org-pomodoro实践番茄工作法

若不安装 aplay(sudo pacman -S alsa-utils)则会在番茄钟结束的时候报错

Error running timer 'org-pomodoro-tick': (error Not found wav player on your system!!")

注:即使安装soxvlcmplayer也会报相同的错误。在我的有限尝试中,只有安装aplay可以解决这个问题。


尽管安装 aplay 后不会报上述错误,在番茄钟结束的时候会报新的错误。

Time for a break.
deferred error : (error "Deferred process exited abnormally:
  command: aplay
  exit status: exit 1
  event: exited abnormally with code 1
  buffer contents: \"Usage: aplay [OPTION]... [FILE]...

-h, --help              help
    --version           print current version
-l, --list-devices      list all soundcards and digital audio devices
-L, --list-pcms         list device names
-D, --device=NAME       select PCM by name
-q, --quiet             quiet mode
-t, --file-type TYPE    file type (voc, wav, raw or au)
-c, --channels=#        channels
-f, --format=FORMAT     sample format (case insensitive)
-r, --rate=#            sample rate
-d, --duration=#        interrupt after # seconds
-s, --samples=#         interrupt after # samples per channel
-M, --mmap              mmap stream
-N, --nonblock          nonblocking mode
-F, --period-time=#     distance between interrupts is # microseconds
-B, --buffer-time=#     buffer duration is # microseconds
    --period-size=#     distance between interrupts is # frames
    --buffer-size=#     buffer duration is # frames
-A, --avail-min=#       min available space for wakeup is # microseconds
-R, --start-delay=#     delay for automatic PCM start is # microseconds 
                        (relative to buffer size if <= 0)
-T, --stop-delay=#      delay for automatic PCM stop is # microseconds from xrun
-v, --verbose           show PCM structure and setup (accumulative)
-V, --vumeter=TYPE      enable VU meter (TYPE: mono or stereo)
-I, --separate-channels one file for each channel
-i, --interactive       allow interactive operation from stdin
-m, --chmap=ch1,ch2,..  Give the channel map to override or follow
    --disable-resample  disable automatic rate resample
    --disable-channels  disable automatic channel conversions
    --disable-format    disable automatic format conversions
    --disable-softvol   disable software volume control (softvol)
    --test-position     test ring buffer position
    --test-coef=#       test coefficient for ring buffer position (default 8)
                        expression for validation is: coef * (buffer_size / 2)
    --test-nowait       do not wait for ring buffer - eats whole CPU
    --max-file-time=#   start another output file when the old file has recorded
                        for this many seconds
    --process-id-file   write the process ID here
    --use-strftime      apply the strftime facility to the output file name
    --dump-hw-params    dump hw_params of the device
    --fatal-errors      treat all errors as fatal
Recognized sample formats are: S8 U8 S16_LE S16_BE U16_LE U16_BE S24_LE S24_BE U24_LE U24_BE S32_LE S32_BE U32_LE U32_BE FLOAT_LE FLOAT_BE FLOAT64_LE FLOAT64_BE IEC958_SUBFRAME_LE IEC958_SUBFRAME_BE MU_LAW A_LAW IMA_ADPCM MPEG GSM S20_LE S20_BE U20_LE U20_BE SPECIAL S24_3LE S24_3BE U24_3LE U24_3BE S20_3LE S20_3BE U20_3LE U20_3BE S18_3LE S18_3BE U18_3LE U18_3BE G723_24 G723_24_1B G723_40 G723_40_1B DSD_U8 DSD_U16_LE DSD_U32_LE DSD_U16_BE DSD_U32_BE
Some of these may not be available on selected hardware
The available format shortcuts are:
-f cd (16 bit little endian, 44100, stereo)
-f cdr (16 bit big endian, 44100, stereo)
-f dat (16 bit little endian, 48000, stereo)
\"")

我的配置如下:

(require 'sound-wav)
(use-package org-pomodoro
  :after org
  :config
  (setq org-pomodoro-audio-player "mplayer"
        org-pomodoro-start-sound "sounds/focus_bell.wav"
        org-pomodoro-short-break-sound "sounds/three_beeps.wav"
        org-pomodoro-long-break-sound "sounds/three_beeps.wav"
        org-pomodoro-finished-sound "sounds/meditation_bell.wav")
  (defun org-pomodoro-prompt ()
    (interactive)
    (org-clock-goto)
    (if (y-or-n-p "Start a new pomodoro?")
        (progn
          (org-pomodoro))))
  )

请问该怎么解决这个问题呢?感谢~!

这应该是 aplay 的问题吧。 你试试直接shell 执行 aplay ~/.emacs.d/elpa-29.0/org-pomodoro-20220318.1618/resources/bell.wav 我也是archlinux 默认的配置,可以正常的工作。

1 个赞
  1. 如果你用 mplayer,加入这段配置:
(setq pomidor-play-sound-file
      (lambda (file)
        (start-process "my-pomidor-play-sound"
                       nil
                       "mplayer"
                       file)))
  1. 如果你使用 mpv,可以尝试这段配置(在 macos 上能用,但每次都会打开一个 mpv 实例):
  (setq pomidor-play-sound-file
	(lambda (file)
          (start-process "my-pomidor-play-sound"
			 nil
			 "mpv"
			 "--player-operation-mode=pseudo-gui"
			 file)))

  1. 如果你不想要声音,可以 (setq pomidor-play-sound-file nil)
1 个赞

我也用上了。我加了个hook,时间一到打开一个图片:

(add-hook 'org-pomodoro-finished-hook
            (lambda ()
              (find-file "~/pattern.png")
              (image-transform-fit-to-width)))
1 个赞

后面发现可能是路径问题,将配置改了一下,就ok了

(add-to-list 'load-path "~/.emacs.d/lisp/")
(require 'org-pomodoro)

(use-package org-pomodoro
  :after org
  :config
  (setq org-pomodoro-audio-player (or (executable-find "aplay") (executable-find "afplay"))
        org-pomodoro-play-sounds t           ; Determines whether soudns are played or not
        
        org-pomodoro-start-sound-p t         ; Determine whether to play a sound when a pomodoro started
        org-pomodoro-start-sound (expand-file-name "sounds/focus_bell.wav" user-emacs-directory)
        org-pomodoro-length 1                ; The length of a pomodoro in minutes

        org-pomodoro-finished-sound-p t      ; Determines whether to play a sound when a pomodoro finished
        org-pomodoro-finished-sound (expand-file-name "sounds/meditation_bell.wav" user-emacs-directory)

        org-pomodoro-manual-break t          ; Whether the user needs to exit manually from a running pomodoro to enter a break
        org-pomodoro-overtime-sound-p t      ; Determines whether to play a sound when a pomodoro starts to run overtime
        org-pomodoro-overtime-sound (expand-file-name "sounds/meditation_bell.wav" user-emacs-directory)

        org-pomodoro-clock-break t           ; Whether to clock time during breaks

        org-pomodoro-short-break-sound-p t   ; Determines whether to play a sound when a short-break finished
        org-pomodoro-short-break-sound (expand-file-name "sounds/focus_bell.wav" user-emacs-directory)
        org-pomodoro-short-break-length 1    ; The length of a short break in minutes

        org-pomodoro-long-break-sound-p t    ; Determines whether to play sound when a long-break finished
        org-pomodoro-long-break-sound (expand-file-name "sounds/focus_bell.wav" user-emacs-directory)
        org-pomodoro-long-break-frequency 4  ; The maximum number of pomodoros until a long break is started
        org-pomodoro-long-break-length 1     ; The length of a long break in minutes
        )
  )

另外 @Imymirror 大佬提到的 pomidor 插件也蛮酷的