将音频录制到 pulseaudio 流/接收器输入,并根据需要从流播放

将音频录制到 pulseaudio 流/接收器输入,并根据需要从流播放

我正在使用 CS42888 编解码器来录制来自线路输入的音频。我读过这个帖子使用 PulseAudio 记录程序的输出并针对我想要实现的目标有了一些想法。但是,我遇到了一些问题。

问题

首先,我目前能够从设备记录的唯一方法如下:

arecord -Dhw:cs42888audio -f S16_LE -r 48000 test.wav

我可以玩:

arecord -Dhw:cs42888audio test.wav

我先介绍一下情况:

  • 将 cs42888audio 输入录制到 pulseaudio 流(在“radio”名称下)

任何一个:

  • 每当“广播”流可用时,我都想将其设为默认流并将其路由到 cs42888 输出。

或者:

  • 始终在后台录制“广播”流。使用一组命令随时播放/流式传输。

我尝试过的方法

pactl list sink-inputs                         # Gives nothing
pactl load-module module-null-sink sink_name=radio
pactl move-sink-input 3 radio                  # Fails
parec --format=s16le --rate=48000 -d alsa_output.platform-sound-cs42888.analog-surround-51.monitor | lame -r --quiet -q 3 --lowpass 17 --abr 192 - "temp.mp3"
aplay -Dhw:cs42888audio temp.mp3               # No audio other than noise

声音配置

我的.asoundrc如下:

pcm.!default {
    type hw
    card 2
    device 0
}

我的 /etc/pulse/system.pa 有:

set-default-source alsa_input.platform-sound.analog-mono
set-default-sink alsa_output.platform-sound.analog-mono

aplay -l 给出:

**** List of PLAYBACK Hardware Devices ****
card 0: cs42888audio [cs42888-audio], device 0: HiFi cs42888-0 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: wm8960audio [wm8960-audio], device 0: HiFi wm8960-hifi-0 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: wm8960audio [wm8960-audio], device 1: HiFi-ASRC-FE (*) []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: amixaudiosai [amix-audio-sai], device 0: HiFi-AMIX-FE (*) []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: amixaudiosai [amix-audio-sai], device 1: HiFi-AMIX-FE (*) []
  Subdevices: 1/1
  Subdevice #0: subdevice #0

arecord -l 给出:

**** List of CAPTURE Hardware Devices ****
card 0: cs42888audio [cs42888-audio], device 0: HiFi cs42888-0 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: wm8960audio [wm8960-audio], device 0: HiFi wm8960-hifi-0 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: wm8960audio [wm8960-audio], device 1: HiFi-ASRC-FE (*) []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: amixaudiosai [amix-audio-sai], device 0: HiFi-AMIX-FE (*) []
  Subdevices: 1/1
  Subdevice #0: subdevice #0

pactl list 短接收器

0   alsa_output.platform-sound-amix-sai.analog-mono module-alsa-card.c  s16le 1ch 48000Hz   SUSPENDED
1   alsa_output.platform-sound-cs42888.analog-surround-51   module-alsa-card.c  s16le 6ch 48000Hz   SUSPENDED
2   alsa_output.platform-sound.analog-mono  module-alsa-card.c  s16le 1ch 48000Hz   SUSPENDED

pactl 列出简短来源

0   alsa_output.platform-sound-amix-sai.analog-mono.monitor module-alsa-card.c  s16le 1ch 48000Hz   SUSPENDED
1   alsa_input.platform-sound-amix-sai.analog-mono  module-alsa-card.c  s16le 1ch 48000Hz   SUSPENDED
2   alsa_output.platform-sound-cs42888.analog-surround-51.monitor   module-alsa-card.c  s16le 6ch 48000Hz   SUSPENDED
3   alsa_input.platform-sound-cs42888.analog-mono   module-alsa-card.c  s16le 1ch 48000Hz   SUSPENDED
4   alsa_output.platform-sound.analog-mono.monitor  module-alsa-card.c  s16le 1ch 48000Hz   SUSPENDED
5   alsa_input.platform-sound.analog-mono   module-alsa-card.c  s16le 1ch 48000Hz   SUSPENDED

非常感谢您的指导。谢谢。

答案1

解决了!

pactl load-module module-loopback source=alsa_input.platform-sound-cs42888.analog-mono sink=alsa_output.platform-sound-cs42888.analog-surround-51 rate=48000

但是, pactl unload-module module-loopback效果不太好,要等几秒钟。要是能立刻卸载就好了。

相关内容