在使用程序调用音频设备的时候可能会出现无法播放音频,或者无法使用麦克风的问题。需要进行音频输入输出的检测,然后根据情况选中默认的音频设备。
1、查看输出、输出音频的控制
1. 查看音频设备
如果你的系统有 /proc/asound/cards 路径,说明 ALSA 驱动已经使用上,可查看 sound devices。
执行以下命令可看到当前的音频设备。
$ cat /proc/asound/cards
0 [tegrahdaxnx ]: tegra-hda-xnx - tegra-hda-xnx
tegra-hda-xnx at 0x3518000 irq 65
1 [jetsonxaviernxa]: jetson-xaviernx - jetson-xaviernx-ape
jetson-xaviernx-ape
2 [ArrayUAC10 ]: USB-Audio - ReSpeaker 4 Mic Array (UAC1.0)
SEEED ReSpeaker 4 Mic Array (UAC1.0) at usb-3610000.xhci-2.1, full speed
或者使用如下命令
cat /proc/asound/devices
$ ll /proc/asound/
total 0
dr-xr-xr-x 5 root root 0 11月 15 17:41 ./
dr-xr-xr-x 306 root root 0 1月 1 1970 ../
lrwxrwxrwx 1 root root 5 11月 15 18:27 ArrayUAC10 -> card2/
dr-xr-xr-x 6 root root 0 11月 15 18:27 card0/
dr-xr-xr-x 42 root root 0 11月 15 18:27 card1/
dr-xr-xr-x 4 root root 0 11月 15 18:27 card2/
-r--r--r-- 1 root root 0 11月 15 18:27 cards
-r--r--r-- 1 root root 0 11月 15 18:27 devices
-r--r--r-- 1 root root 0 11月 15 18:27 hwdep
lrwxrwxrwx 1 root root 5 11月 15 18:27 jetsonxaviernxa -> card1/
-r--r--r-- 1 root root 0 11月 15 18:27 pcm
lrwxrwxrwx 1 root root 5 11月 15 18:27 tegrahdaxnx -> card0/
-r--r--r-- 1 root root 0 11月 15 18:27 timers
-r--r--r-- 1 root root 0 11月 15 18:27 version
2. 查看音频的输入输出
#查看所有的音频输入
arecord -l
#录制音频 ,10S
arecord -d 10 /tmp/t.wav
#查看所有的音频输出
aplay -l
#播放
aplay a.wav
2. 设置默认的音频设备
2、查看输入音频的控制
3、注意事项
1) 普通用户开通所有串口的方法
Linux下的设备使用都需要使用sudo或root用户才能打开,为了能让普通用户也能使用串口,
可以增加udev规则来实现,具体方法如下(配置完成后,重启服务器):
sudo vim /etc/udev/rules.d/70-ttyusb.rules
增加如下内容:
KERNEL=="ttyUSB[0-9]*",MODE="0666"
2) java无法调用音频流的问题
Put this text in the file /etc/systemd/system/pulseaudio.service:
[Unit]
Description=PulseAudio system server
# DO NOT ADD ConditionUser=!root
[Service]
Type=notify
Exec=pulseaudio --daemonize=no --system --realtime --log-target=journal
Restart=on-failure
[Install]
WantedBy=multi-user.target
This unit file is a straightforward method that starts PulseAudio and makes sure it is running.
Now enable and start this unit file by running the following commands:
systemctl --system enable --now pulseaudio.service
It should be running now. You can check the status of the service with the command:
systemctl --system status pulseaudio.service