【平头哥Sipeed LicheeRV 86 Panel测评】11-音频录放测试
<h1 cid="n16" mdtype="heading">1 Linux下ALSA音频工具</h1><p cid="n23" mdtype="paragraph">ALSA(Advanced Linux Sound Architecture)是linux上主流的音频结构</p>
<p cid="n18" mdtype="paragraph"><a href="https://www.alsa-project.org/wiki/Main_Page">https://www.alsa-project.org/wiki/Main_Page</a></p>
<p cid="n19" mdtype="paragraph"></p>
<p cid="n4" mdtype="paragraph">ALSA常用的工具包括:</p>
<ul cid="n25" data-mark="-" mdtype="list">
<li cid="n27" mdtype="list_item">
<p cid="n28" mdtype="paragraph">arecord:音频录制</p>
</li>
<li cid="n31" mdtype="list_item">
<p cid="n29" mdtype="paragraph">aplay:音频播放</p>
</li>
<li cid="n34" mdtype="list_item">
<p cid="n32" mdtype="paragraph">amixer:音频参数设置</p>
</li>
</ul>
<h2 cid="n37" mdtype="heading">1.1 音频录制arecord介绍</h2>
<p cid="n6" mdtype="paragraph">查看arecord的帮助信息</p>
<pre>
<code class="language-bash">root@MaixLinux:/# arecord -h
Usage: arecord ... ...
-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
-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-resampledisable automatic rate resample
--disable-channelsdisable 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 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)
root@MaixLinux:/#</code></pre>
<p cid="n10" mdtype="paragraph">查看音频录制设备</p>
<pre>
<code class="language-bash">root@MaixLinux:/# arecord -l
**** List of CAPTURE Hardware Devices ****
card 0: audiocodec , device 0: SUNXI-CODEC 2030000.codec-0 []
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: snddmic , device 0: 2031000.dmic-dmic-hifi dmic-hifi-0 []
Subdevices: 1/1
Subdevice #0: subdevice #0
card 2: sndhdmi , device 0: 2034000.daudio-audiohdmi-dai 20340a4.hdmiaudio-0 []
Subdevices: 1/1
Subdevice #0: subdevice #0
root@MaixLinux:/#</code></pre>
<h2 cid="n14" mdtype="heading">1.2 音频播放aplay介绍</h2>
<p cid="n40" mdtype="paragraph">查看aplay的帮助信息</p>
<pre>
<code class="language-bash">root@MaixLinux:/# aplay -h
Usage: aplay ... ...
-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
-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-resampledisable automatic rate resample
--disable-channelsdisable 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 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)
root@MaixLinux:/#</code></pre>
<p cid="n44" mdtype="paragraph">查看音频播放设备</p>
<pre>
<code class="language-bash">root@MaixLinux:/# aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: audiocodec , device 0: SUNXI-CODEC 2030000.codec-0 []
Subdevices: 1/1
Subdevice #0: subdevice #0
card 2: sndhdmi , device 0: 2034000.daudio-audiohdmi-dai 20340a4.hdmiaudio-0 []
Subdevices: 1/1
Subdevice #0: subdevice #0
root@MaixLinux:/#</code></pre>
<h2 cid="n49" mdtype="heading">1.3 参数设置amixer介绍</h2>
<p cid="n55" mdtype="paragraph">amixer用于配置声卡的各个选项</p>
<pre>
<code class="language-bash">root@MaixLinux:/# amixer -h
Usage: amixer <options>
Available options:
-h,--help this help
-c,--card N select the card
-D,--device N select the device, default 'default'
-d,--debug debug mode
-n,--nocheck do not perform range checking
-v,--version print version of this program
-q,--quiet be quiet
-i,--inactive show also inactive controls
-a,--abstract L select abstraction level (none or basic)
-s,--stdin Read and execute commands from stdin sequentially
-R,--raw-volume Use the raw value (default)
-M,--mapped-volume Use the mapped volume
Available commands:
scontrols show all mixer simple controls
scontents show contents of all mixer simple controls (default command)
sset sID P set contents for one mixer simple control
sget sID get contents for one mixer simple control
controls show all controls for given card
contents show contents of all controls for given card
cset cID P set control contents for one control
cget cID get control contents for one control
root@MaixLinux:/#</code></pre>
<p cid="n62" mdtype="paragraph">amixer还可以使用图像界面操作,对应的是alsamixer命令,可以通过键盘的上下键,左右键等,设置需要的音量。不过板子中的alsamixer打开之后,部分显示为乱码,不知道什么原因:</p>
<p cid="n68" mdtype="paragraph"></p>
<h1 cid="n60" mdtype="heading">2 音频录制与播放测试</h1>
<h2 cid="n70" mdtype="heading">2.1 录制音频</h2>
<p cid="n81" mdtype="paragraph">使用如下指令即可使用板子自带的麦克风录制音频:</p>
<pre>
<code class="language-bash">arecord -D hw:1,0 -f S16_LE -t wav -d 3 t.wav </code></pre>
<ul cid="n84" data-mark="-" mdtype="list">
<li cid="n86" mdtype="list_item">
<p cid="n87" mdtype="paragraph">-D:用于指定录音设备,这里是hw:1,0设备</p>
</li>
<li cid="n90" mdtype="list_item">
<p cid="n88" mdtype="paragraph">-f:用于指定音频格式,这里是S16_LE格式</p>
</li>
<li cid="n94" mdtype="list_item">
<p cid="n92" mdtype="paragraph">-t:用于指定文件格式,这里是wav格式</p>
</li>
<li cid="n116" mdtype="list_item">
<p cid="n114" mdtype="paragraph">-d:用于指定录音时长,单位是秒,这里是3秒</p>
</li>
<li cid="n140" mdtype="list_item">
<p cid="n138" mdtype="paragraph">最后是输出的音频文件:输出到当前目录的t.wav文件中</p>
</li>
</ul>
<h2 cid="n72" mdtype="heading">2.2 播放音频</h2>
<p cid="n122" mdtype="paragraph">使用如下指令即可播放音频:</p>
<pre>
<code class="language-bash">aplay -D hw:0,0 t.wav</code></pre>
<ul cid="n130" data-mark="-" mdtype="list">
<li cid="n132" mdtype="list_item">
<p cid="n133" mdtype="paragraph">-D:用于指定录音设备,这里是hw:1,0设备</p>
</li>
<li cid="n136" mdtype="list_item">
<p cid="n134" mdtype="paragraph">最后是要播放的音频文件:刚才录制的t.wav音频文件</p>
</li>
</ul>
<p cid="n125" mdtype="paragraph">除了使用录制的音频,还可以使用第三方软件来合成一些我们需要的语音进行播放,比如录制一段天气预报的语音并播放:</p>
<pre>
<code class="language-bash">root@MaixLinux:/audio# ls
nmc0320.wavt.wav
root@MaixLinux:/audio# aplay -D hw:0,0 nmc0320.wav
Playing WAVE 'nmc0320.wav' : Signed 16 bit Little Endian, Rate 16000 Hz, Mono</code></pre>
<p cid="n144" mdtype="paragraph"><iframe __idm_id__="188417" allowfullscreen="true" frameborder="0" height="450" src="//player.bilibili.com/player.html?bvid=1aZ4y1677f&page=1" style="background:#eee;margin-bottom:10px;" width="700"></iframe><br />
</p>
<h1 cid="n74" mdtype="heading">3 总结</h1>
<p cid="n146" mdtype="paragraph">本篇介绍了LicheeRV 86 Panel音频录制与播放功能。</p>
<p> </p>
<p>声音还行比较清晰</p>
页:
[1]