使用Racket RSound无法获得声音

时间:2019-09-01 02:11:47

标签: racket playback

我正在尝试使用Racket Rsound播放声音。我在FullScreen中有一个简单的程序正在与play.rkt一起运行。

使用GUI库中的racket play.rkt会播放声音,就像我期望的那样:

play-sound

输出:

#lang racket/base
(require racket/gui/base)
(play-sound "/media/tamayo/ExtraDrive1/Dropbox/fclooper/poc/sample.wav" #t)

但是使用RSound不会播放任何音频:

$ racket play.rkt
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
#t ;; plays audio correctly

除了最后一行是#lang racket/base (require rsound) (play (rs-read "/media/tamayo/ExtraDrive1/Dropbox/fclooper/poc/sample.wav")) 而不是"played sound"以外,输出与上面相同。

呼叫#t也会失败:

andplay

当我直接从Racket REPL中运行相同的代码时,它也可以正确播放音频:

#lang racket/base

(require rsound)
(andplay (rs-read "/media/tamayo/ExtraDrive1/Dropbox/fclooper/poc/sample.wav" #t))

因此REPL知道如何通过RSound正确播放音频,并且$ racket Welcome to Racket v7.3. > (require rsound) ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map Cannot connect to server socket err = No such file or directory Cannot connect to server request channel jack server is not running or cannot be started JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock > (play (rs-read "/media/tamayo/ExtraDrive1/Dropbox/fclooper/poc/sample.wav")) "played sound" ;; <-- and it does. > 可以使用racket播放,但是我的程序失败了。为什么?

详细信息

Ubuntu 18.04

(play-sound ...)

2 个答案:

答案 0 :(得分:1)

事实证明,该程序只是在退出之前才有机会真正播放声音!

我想这应该使我了解RSound异步工作的事实:

  

与已经播放的声音同时播放

这也解释了为什么REPL有效但CLI却不起作用,因为REPL等待用户输入,同时继续在后台运行代码。

就目前而言,一个简单的sleep hack可以工作:

#lang racket/base
(play (rs-read "/media/tamayo/ExtraDrive1/Dropbox/fclooper/poc/sample.wav"))
(sleep 10)

(这是循环程序的一部分,该程序永远运行,等待用户输入以执行诸如交换示例声音的操作。显然,此问题超出了此范围,因此sleep是目前的解决方法,但在实际的GUI版本中将变得无关紧要。)

答案 1 :(得分:0)

根据the documentation for play,该功能不能在子模块main中使用。

您可以使用以下功能:

#lang racket/base
(play (rs-read "/media/tamayo/ExtraDrive1/Dropbox/fclooper/poc/sample.wav"))