gpt4 book ai didi

linux - 播放正在写入的 MP3 文件

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:38:35 27 4
gpt4 key购买 nike

我正在使用 rtl_fm 和 sox 将调频电台保存到 mp3 文件。rtl_fm 捕获信号和 sox 将其转码为 mp3。

rtl_fm  -M  wbfm  -f  88.1M -d 0 -s 22050k -l 310 | sox -traw -r8k -es -b16 -c1 -V1 - -tmp3 - | sox -tmp3 - some_file.mp3

然后我尝试在第二个终端中播放该文件,因为正在使用以下方式编写 mp3:

play -t mp3 some_file.mp3

问题是它只播放到调用播放命令时 mp3 的时间。

如何让它在写入时随时间播放附加的 mp3?

编辑:在 Raspberry Pi 3 (Raspian Jessie) 上运行,NooElec R820T SDR

最佳答案

这里有几件事。我认为 sox 不支持“拖尾”文件,但我知道 mplayer 支持。但是,为了更好地控制管道,使用 gstreamer 可能是可行的方法,因为它在其效果管道中内置了并行事件流。

如果你想坚持使用 sox,我会首先摆脱 sox 的冗余第二次调用,例如:

rtl_fm -M wbfm -f 88.1M -d 0 -s 22050k -l 310 |
sox -ts16 -r8k -c1 -V1 - some_file.mp3

为了在转码的同时播放流,您可以使用 tee 对其进行多路复用,例如:

rtl_fm -M wbfm -f 88.1M -d 0 -s 22050k -l 310 |
tee >(sox -ts16 -r8k -c1 -V1 - some_file.mp3) |
play -ts16 -r8k -c1 -

或者如果您希望它们是单独的进程:

# Save stream to a file
rtl_fm -M wbfm -f 88.1M -d 0 -s 22050k -l 310 > some_file.s16

# Encode stream
sox -ts16 -r8k -c1 -V1 some_file.s16 some_file.mp3

# Start playing the file at 10 seconds in
tail -c+$((8000 * 10)) -f some_file.s16 |
play -ts16 -r8k -c1 -

关于linux - 播放正在写入的 MP3 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45578317/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com