“How to record audio”的版本间的差异

来自百问网嵌入式Linux wiki
第1行: 第1行:
{{DISPLAYTITLE:如何录制音频}}
+
== Article purpose ==
 +
This article explains how to record audio via the kernel [[ALSA overview|ALSA]] audio framework in '''Linux® OS''' context.
 +
The examples below, show how to record audio from the different audio hardware interfaces of the STM32MPU [[:Category:ST boards| boards]].
  
=如何录制音频=
+
== Audio record overview ==
==文章目的==
+
The [[ALSA overview|ALSA]] framework exposes audio devices associated to the board audio hardware interfaces.
: 本文介绍如何通过具备内核音频 ALSA 的音频框架的 Linux® 操作系统环境录制音频。以下示例显示了如何从 STM32MPU 板载的不同音频硬件接口录制音频。
 
  
==概述==
+
The application audio streams are routed by default through the [[PulseAudio]] sound server. PulseAudio exposes audio profiles, which are mapped on the ALSA sound card audio devices. The PulseAudio server provides a command line interface to list audio profiles and to select one, in order to record from a specific audio interface.
: ALSA 框架公开了与板音频硬件接口关联的音频设备。
 
: 默认情况下,应用程序音频流通过PulseAudio声音服务器进行路由。PulseAudio公开音频配置文件,这些配置文件映射在ALSA声卡音频设备上。PulseAudio服务器提供了一个命令行界面来列出相应的音频配置文件并进行选择,以便从特定的音频接口进行录制。
 
: 以下各节中的音频记录示例均基于 ALSA 实用程序。一些输入路径是通过 ALSA 控件配置的。声卡配置文章中详细介绍了这些配置。如果在运行示例时发出错误,请参阅音频故障排除文章以进行调试。
 
  
==例子==
+
The audio record examples in following sections are based on [[ALSA_overview#How_to_use|ALSA utilities]]. Some input paths are configured through ALSA controls. These configurations are detailed in [[Soundcard_configuration|sound card configuration]] article. If an error is issued when running an example, please refer to [[Audio troubleshooting grid]] article for debug.
===来自耳机麦克风输入的音频记录===
 
====从 ALSA 设备记录====
 
: 从 “record_codec” ALSA 设备开始音频记录:
 
  
: 注意:“record_codec” 是在 /etc/asound.conf 中定义的别名,用于耳机麦克风输入设备。
+
== Examples ==
<syntaxhighlight lang="bash">
 
Board $> arecord -D record_codec -f S16_LE -d 10 /tmp/rec.wav
 
</syntaxhighlight>
 
====通过 PulseAudio 录制===
 
=====对于生态系统版本 ≥ v1.2.0 =====
 
: 配置Pulseaudio:
 
:: 将Pulseaudio的默认输入源更改为'analog_input':
 
  
:: 注意:Pulseaudio模拟输入在/etc/pulse/system.pa配置文件中定义。
+
=== Audio record from headset microphone input ===
<syntaxhighlight lang="bash">
 
Board $> pacmd set-default-source analog_input
 
</syntaxhighlight>
 
: 开始录音:
 
: 注意:Pulseaudio设备是默认设备,因此在记录命令中可以省略 “-D pulse” 选项。
 
<syntaxhighlight lang="bash">
 
Board $> arecord -d 10 /tmp/rec.wav
 
</syntaxhighlight>
 
=====对于生态系统版本 ≤ v1.1.0 =====
 
===来自数字麦克风输入的音频记录===
 
: 注意:数字麦克风输入的支持取决于电路板。请使用“ arecord -l ”命令检查可用的输入。
 
==从ALSA设备记录====
 
: 从 “record_dfsdm0” ALSA设备开始单声道音频记录:
 
  
: 注意:“record_dfsdm0”是在/etc/asound.conf中定义的别名,用于数字麦克风 U1 输入设备。
+
==== Record from ALSA device ====
<syntaxhighlight lang="bash">
+
Start audio record from 'record_codec' ALSA device:
Board $> arecord -D record_dfsdm0 -r 16000 -f S32_LE -c 1 -d 10 /tmp/rec.wav
 
</syntaxhighlight>
 
====从虚拟ALSA设备录制多个数字麦克风====
 
从“多个” ALSA设备开始立体声音频记录:
 
  
: 注意:基于 ALSA 多重插件[1 ]的 “多重”设备必须在 /etc/asound.conf 文件中定义。
+
{{Info|'record_codec' is an alias defined in /etc/asound.conf, for headset microphone input device.}}
<syntaxhighlight lang="bash">
+
{{Board$}} arecord -D record_codec -f S16_LE -d 10 /tmp/rec.wav
Board $> arecord -D multi -r 16000 -f S32_LE -c 2 -d 10 /tmp/rec.wav
 
</syntaxhighlight>
 
====通过 PulseAudio 录制====
 
: 通过 Pulseaudio 进行的记录仅适用于 v1.2.0 或更高版本的生态系统 。
 
  
: 配置 Pulseaudio
+
==== Record via PulseAudio ====
: 将 Pulseaudio 的默认输入源更改为 “dmic1_input”:
 
  
: 注意:Pulseaudio dmic1_input 在 /etc/pulse/system.pa 配置文件中定义。
+
===== For {{EcosystemRelease | revision=1.2.0 | range=and after}} =====
<syntaxhighlight lang="bash">
 
Board $> pacmd set-default-source dmic1_input
 
</syntaxhighlight>
 
: 开始录音:
 
: 注意:Pulseaudio 设备是默认设备,因此在记录命令中可以省略 “-D pulse” 选项。
 
<syntaxhighlight lang="bash">
 
Board $> arecord -r 48000 -f S32_LE -c 2 -d 10 /tmp/rec.wav
 
</syntaxhighlight>
 
===来自 S/PDIF 输入的音频记录===
 
: 注意:S/PDIF 输入的支持取决于开发板的硬件支持。使用“ arecord -l ”命令检查可用的输入。
 
====从 ALSA 设备记录====
 
: 从“ record_spdif” ALSA设备开始音频记录:
 
  
: 注意:'record_spdif'是在 /etc/asound.conf 中为 S/PDIF 输入设备定义的别名。
+
* '''Configure Pulseaudio :'''
: 注意:在开始记录命令之前,S/PDIF RCA 输入连接器上必须有 S/PDIF 信号。 记录速率必须根据 S/PDIF 信号采样速率进行设置。
+
Change Pulseaudio default input source to 'analog_input':
<syntaxhighlight lang="bash">
+
{{Info|The Pulseaudio analog_input is defined in /etc/pulse/system.pa configuration file.}}
Board $> arecord -D record_spdif -f S32_LE -c 2 -r 48000 -d 10 /tmp/rec.wav
+
{{Board$}} pacmd set-default-source analog_input
</syntaxhighlight>
 
====通过 PulseAudio 录制====
 
: 通过 Pulseaudio 进行的记录仅适用于 v1.2.0 或更高版本的生态系统 。
 
  
: 配置 Pulseaudio
+
* '''Start audio record :'''
: 将 Pulseaudio 的默认输入源更改为 “iec958_input”:
+
{{Info|The Pulseaudio device is the default one, so "-D pulse" option can be omitted in the record command.}}
 +
{{Board$}} arecord -d 10 /tmp/rec.wav
  
: 注意:Pulseaudio iec958_input 在 /etc/pulse/system.pa 配置文件中定义。
+
<div class="mw-collapsible mw-collapsed">
<syntaxhighlight lang="bash">
+
===== For {{EcosystemRelease | revision=1.1.0  | range=and before}} =====
Board $> pacmd set-default-source iec958_input
+
<div class="mw-collapsible-content">
</syntaxhighlight>
+
* '''Configure Pulseaudio :'''
: 开始录音:
+
Change Pulseaudio active profile of the sound card, to 'analog-stereo' profile:
: 注意:Pulseaudio 设备是默认设备,因此在记录命令中可以省略 “-D pulse” 选项。
+
{{Info|Example below is given for {{highlight|sound card index 0}}. Check sound cards index with "''pactl list cards short''" command.}}
<syntaxhighlight lang="bash">
+
{{Board$}} pacmd set-card-profile 0 output:analog-stereo+input:analog-stereo
Board $> arecord -r 48000 -f S32_LE -c 2 -d 10 /tmp/rec.wa
 
</syntaxhighlight>
 
==参考==
 
: [https://www.alsa-project.org/alsa-doc/alsa-lib/pcm_plugins.html%7C ALSA PCM插件]
 
  
[[Category:Linux_Operating_System]]
+
* '''Start audio record :'''
[[Category:Audio]]
+
{{Info|The Pulseaudio device is the default one, so "-D pulse" option can be omitted in the record command.}}
[[Category:ALSA]]
+
{{Board$}} arecord -d 10 /tmp/rec.wav
 +
</div></div>
 +
 
 +
=== Audio record from digital microphone input ===
 +
{{Warning|The support of digital microphone input is board dependent. Please, check available inputs with "''arecord -l''" command.}}
 +
 
 +
==== Record from ALSA device ====
 +
Start mono audio record from 'record_dfsdm0' ALSA device:
 +
{{Info|'record_dfsdm0' is an alias defined in /etc/asound.conf, for digital microphone U1 input device.}}
 +
{{Board$}} arecord -D record_dfsdm0 -r 16000 -f S32_LE -c 1 -d 10 /tmp/rec.wav
 +
 
 +
==== Record multiple digital microphones from a virtual ALSA device ====
 +
Start stereo audio record from 'multi' ALSA device:
 +
{{Info|'multi' device, based on ALSA multi plugin<ref>[https://www.alsa-project.org/alsa-doc/alsa-lib/pcm_plugins.html| ALSA PCM plugins]</ref>, has to be defined in /etc/asound.conf file.}}
 +
{{Board$}} arecord -D multi -r 16000 -f S32_LE -c 2 -d 10 /tmp/rec.wav
 +
 
 +
==== Record via PulseAudio ====
 +
The record via Pulseaudio is only available for {{EcosystemRelease | revision=1.2.0 | range=and after}}.
 +
 
 +
* '''Configure Pulseaudio'''
 +
Change Pulseaudio default input source to 'dmic1_input':
 +
{{Info|The Pulseaudio dmic1_input is defined in /etc/pulse/system.pa configuration file.}}
 +
{{Board$}} pacmd set-default-source dmic1_input
 +
 
 +
* '''Start audio record :'''
 +
{{Info|The Pulseaudio device is the default one, so "-D pulse" option can be omitted in the record command.}}
 +
{{Board$}} arecord -r 48000 -f S32_LE -c 2 -d 10 /tmp/rec.wav
 +
 
 +
=== Audio record from S/PDIF input ===
 +
{{Warning|The support of S/PDIF input is board dependent. Please, check available inputs with "''arecord -l''" command.}}
 +
 
 +
==== Get IEC958 status bits ====
 +
Some restrictions may apply to IEC958 control, depending on the SPDIFRX device configuration as it is explained in [[SPDIFRX device tree configuration]] and [[SPDIFRX Linux driver]] articles.
 +
 
 +
{{Board$}} amixer -c STM32MP1EV cget iface=PCM,name='IEC958 Capture Default'
 +
 
 +
==== Record from ALSA device ====
 +
Start audio record from 'record_spdif' ALSA device:
 +
{{Info|'record_spdif' is an alias defined in /etc/asound.conf, for S/PDIF input device.}}
 +
{{Info|A S/PDIF signal must be available on S/PDIF RCA input connector before starting the record command. The record rate must be set according to S/PDIF signal sampling rate.}}
 +
{{Board$}} arecord -D record_spdif -f S32_LE -c 2 -r 48000 -d 10 /tmp/rec.wav
 +
 
 +
==== Record via PulseAudio ====
 +
The record via Pulseaudio is only available for {{EcosystemRelease | revision=1.2.0 | range=and after}}.
 +
 
 +
* '''Configure Pulseaudio'''
 +
Change Pulseaudio default input source to 'iec958_input':
 +
{{Info|The Pulseaudio iec958_input is defined in /etc/pulse/system.pa configuration file.}}
 +
{{Board$}} pacmd set-default-source iec958_input
 +
 
 +
* '''Start audio record :'''
 +
{{Info|The Pulseaudio device is the default one, so "-D pulse" option can be omitted in the record command.}}
 +
{{Board$}} arecord -r 48000 -f S32_LE -c 2 -d 10 /tmp/rec.wav
 +
 
 +
== References ==
 +
<references />
 +
 
 +
<noinclude>
 +
{{PublicationRequestId | 10588 | 2019-02-06}}
 +
[[Category:How to run use cases]]
 +
[[Category:ALSA]]
 +
</noinclude>

2020年5月7日 (四) 11:07的版本

Article purpose

This article explains how to record audio via the kernel ALSA audio framework in Linux® OS context. The examples below, show how to record audio from the different audio hardware interfaces of the STM32MPU boards.

Audio record overview

The ALSA framework exposes audio devices associated to the board audio hardware interfaces.

The application audio streams are routed by default through the PulseAudio sound server. PulseAudio exposes audio profiles, which are mapped on the ALSA sound card audio devices. The PulseAudio server provides a command line interface to list audio profiles and to select one, in order to record from a specific audio interface.

The audio record examples in following sections are based on ALSA utilities. Some input paths are configured through ALSA controls. These configurations are detailed in sound card configuration article. If an error is issued when running an example, please refer to Audio troubleshooting grid article for debug.

Examples

Audio record from headset microphone input

Record from ALSA device

Start audio record from 'record_codec' ALSA device:

Info.png 'record_codec' is an alias defined in /etc/asound.conf, for headset microphone input device.
Board $> arecord -D record_codec -f S16_LE -d 10 /tmp/rec.wav

Record via PulseAudio

For ecosystem release ≥ v1.2.0{{#set:Ecosystem release=revision of a previous flow 1.2.0}}
  • Configure Pulseaudio :

Change Pulseaudio default input source to 'analog_input':

Info.png The Pulseaudio analog_input is defined in /etc/pulse/system.pa configuration file.
Board $> pacmd set-default-source analog_input
  • Start audio record :
Info.png The Pulseaudio device is the default one, so "-D pulse" option can be omitted in the record command.
Board $> arecord -d 10 /tmp/rec.wav
For ecosystem release ≤ v1.1.0{{#set:Ecosystem release=revision of a previous flow 1.1.0}}
  • Configure Pulseaudio :

Change Pulseaudio active profile of the sound card, to 'analog-stereo' profile:

Info.png Example below is given for sound card index 0. Check sound cards index with "pactl list cards short" command.
Board $> pacmd set-card-profile 0 output:analog-stereo+input:analog-stereo
  • Start audio record :
Info.png The Pulseaudio device is the default one, so "-D pulse" option can be omitted in the record command.
Board $> arecord -d 10 /tmp/rec.wav

Audio record from digital microphone input

Warning.png The support of digital microphone input is board dependent. Please, check available inputs with "arecord -l" command.

Record from ALSA device

Start mono audio record from 'record_dfsdm0' ALSA device:

Info.png 'record_dfsdm0' is an alias defined in /etc/asound.conf, for digital microphone U1 input device.
Board $> arecord -D record_dfsdm0 -r 16000 -f S32_LE -c 1 -d 10 /tmp/rec.wav

Record multiple digital microphones from a virtual ALSA device

Start stereo audio record from 'multi' ALSA device:

Info.png 'multi' device, based on ALSA multi plugin[1], has to be defined in /etc/asound.conf file.
Board $> arecord -D multi -r 16000 -f S32_LE -c 2 -d 10 /tmp/rec.wav

Record via PulseAudio

The record via Pulseaudio is only available for ecosystem release ≥ v1.2.0{{#set:Ecosystem release=revision of a previous flow 1.2.0}} .

  • Configure Pulseaudio

Change Pulseaudio default input source to 'dmic1_input':

Info.png The Pulseaudio dmic1_input is defined in /etc/pulse/system.pa configuration file.
Board $> pacmd set-default-source dmic1_input
  • Start audio record :
Info.png The Pulseaudio device is the default one, so "-D pulse" option can be omitted in the record command.
Board $> arecord -r 48000 -f S32_LE -c 2 -d 10 /tmp/rec.wav

Audio record from S/PDIF input

Warning.png The support of S/PDIF input is board dependent. Please, check available inputs with "arecord -l" command.

Get IEC958 status bits

Some restrictions may apply to IEC958 control, depending on the SPDIFRX device configuration as it is explained in SPDIFRX device tree configuration and SPDIFRX Linux driver articles.

Board $> amixer -c STM32MP1EV cget iface=PCM,name='IEC958 Capture Default'

Record from ALSA device

Start audio record from 'record_spdif' ALSA device:

Info.png 'record_spdif' is an alias defined in /etc/asound.conf, for S/PDIF input device.
Info.png A S/PDIF signal must be available on S/PDIF RCA input connector before starting the record command. The record rate must be set according to S/PDIF signal sampling rate.
Board $> arecord -D record_spdif -f S32_LE -c 2 -r 48000 -d 10 /tmp/rec.wav

Record via PulseAudio

The record via Pulseaudio is only available for ecosystem release ≥ v1.2.0{{#set:Ecosystem release=revision of a previous flow 1.2.0}} .

  • Configure Pulseaudio

Change Pulseaudio default input source to 'iec958_input':

Info.png The Pulseaudio iec958_input is defined in /etc/pulse/system.pa configuration file.
Board $> pacmd set-default-source iec958_input
  • Start audio record :
Info.png The Pulseaudio device is the default one, so "-D pulse" option can be omitted in the record command.
Board $> arecord -r 48000 -f S32_LE -c 2 -d 10 /tmp/rec.wav

References


<securetransclude src="ProtectedTemplate:PublicationRequestId" params="10588 | 2019-02-06 |"></securetransclude>