Difference between revisions of "How to record audio"

[quality revision] [pending revision]
imported>Frq08988
m
 
 

1 Article purpose[edit]

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.

2 Audio record overview[edit]

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.

3 Examples[edit]

3.1 Audio record from headset microphone input[edit]

3.1.1 Record from ALSA device[edit]

Launch 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

3.1.2 Record via PulseAudio[edit]

  • Configure Pulseaudio :

For ecosystem release unknown revision:
Change Pulseaudio default input source to 'analog_input':

Info.png The Pulseaudio analog_input is defined in system.pa configuration file.
Board $> pacmd set-default-source analog_input

For ecosystem release ≤ v1.1.0 More info.png:

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

Info.png The Pulseaudio analog-stereo profile is the default profile. So next command is not required after boot.
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

  • Launch audio
record
  • record :
Board $> arecord -d 10 /tmp/rec.wav

3.2 Audio record from digital microphone input[edit]

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

3.2.1 Record from ALSA device[edit]

Launch 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

3.2.2 Record multiple digital microphones from a virtual ALSA device[edit]

Launch 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

3.2.3 Record via PulseAudio (For ecosystem release unknown revision)[edit]

  • Configure Pulseaudio

Change Pulseaudio default input source to 'dmic1_input':

Info.png The Pulseaudio dmic1_input is defined in system.pa configuration file.
Board $> pacmd set-default-source dmic1_input

  • Launch audio record :
Board $> arecord -r 48000 -f S32_LE -c 2 -d 10 /tmp/rec.wav

3.3 Audio record from S/PDIF input[edit]

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

3.3.1 Record from ALSA device[edit]

Launch 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 launching 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

3.3.2 Record via PulseAudio (For ecosystem release unknown revision)[edit]

  • Configure Pulseaudio

Change Pulseaudio default input source to 'iec958_input':

Info.png The Pulseaudio iec958_input is defined in system.pa configuration file.
Board $> pacmd set-default-source iec958_input

  • Launch audio record :
Board $> arecord -r 48000 -f S32_LE -c 2 -d 10 /tmp/rec.wav

4 References[edit]



<noinclude>

{{ArticleMainWriter | OlivierM}}
{{ArticleApprovedVersion | OlivierM | ArnaudP(Passed, 30Janv'18) | No previous approved version | LagoutteJM - 6Feb'19 - 10588 | 6Feb'19}}
[[Category:How to run use cases]]
[[Category:ALSA]]</noinclude>

== 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. 

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_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.

== Examples ==

=== Audio record from headset microphone input ===* '''

==== Record from ALSA device''' ====Launch audio record from 'record_codec' ALSA device:
{{Info|'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'''
Change Pulseaudio ==== Record via PulseAudio ====

* '''Configure Pulseaudio :'''

'''For {{EcosystemRelease | revision=1.2.0 | range=and after}}''':<br />

Change Pulseaudio default input source to 'analog_input':
{{Info|The Pulseaudio analog_input is defined in system.pa configuration file.}}

 {{Board$}} pacmd set-default-source analog_input
<div class="mw-collapsible mw-collapsed">

'''For {{EcosystemRelease | revision=1.1.0  | range=and before}}''':<div class="mw-collapsible-content">

Change Pulseaudio active profile of the sound card, to 'analog-stereo' profile:
{{Info|The Pulseaudio analog-stereo profile is the default profile. So next command is not required after boot.}}
{{Info|Example below is given for {{highlight|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
</div></div>


* '''Launch audio record: :'''

 {{Board$}} arecord -d 10 /tmp/rec.wav

=== 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'''
Launch  ====
Launch 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 ====
Launch 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 (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 system.pa configuration file.}}

 {{Board$}} pacmd set-default-source dmic1_input

* '''Launch audio record :'''
 {{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.}}
* '''==== Record from ALSA device''' ====Launch 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 launching 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 (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 system.pa configuration file.}}

 {{Board$}} pacmd set-default-source iec958_input

* '''Launch audio record :'''
 {{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>
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
<noinclude>
 
{{ArticleMainWriter | OlivierM}}
 
{{ArticleApprovedVersion | OlivierM | ArnaudP(Passed, 30Janv'18) | No previous approved version | LagoutteJM - 6Feb'19 - 10588 | 6Feb'19}}
 
[[Category:How to run use cases]]
 
[[Category:ALSA]]
 
</noinclude>
 
 
 
== Article purpose ==
 
== Article purpose ==
 
This article explains how to record audio via the kernel [[ALSA overview|ALSA]] audio framework in '''Linux® OS''' context.
 
This article explains how to record audio via the kernel [[ALSA overview|ALSA]] audio framework in '''Linux® OS''' context.
Line 20: Line 13:
   
 
=== Audio record from headset microphone input ===
 
=== Audio record from headset microphone input ===
* '''Record from ALSA device'''
+
 
  +
==== Record from ALSA device ====
 
Launch audio record from 'record_codec' ALSA device:
 
Launch audio record from 'record_codec' ALSA device:
 
{{Info|'record_codec' is an alias defined in /etc/asound.conf, for headset microphone input device.}}
 
{{Info|'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
 
  {{Board$}} arecord -D record_codec -f S16_LE -d 10 /tmp/rec.wav
   
* '''Record via PulseAudio'''
+
==== Record via PulseAudio ====
  +
 
  +
* '''Configure Pulseaudio :'''
  +
 
  +
'''For {{EcosystemRelease | revision=1.2.0 | range=and after}}''':<br />
  +
Change Pulseaudio default input source to 'analog_input':
  +
{{Info|The Pulseaudio analog_input is defined in system.pa configuration file.}}
  +
 
  +
{{Board$}} pacmd set-default-source analog_input
  +
 
  +
<div class="mw-collapsible mw-collapsed">
  +
'''For {{EcosystemRelease | revision=1.1.0  | range=and before}}''':
  +
<div class="mw-collapsible-content">
 
Change Pulseaudio active profile of the sound card, to 'analog-stereo' profile:
 
Change Pulseaudio active profile of the sound card, to 'analog-stereo' profile:
 
{{Info|The Pulseaudio analog-stereo profile is the default profile. So next command is not required after boot.}}
 
{{Info|The Pulseaudio analog-stereo profile is the default profile. So next command is not required after boot.}}
 
{{Info|Example below is given for {{highlight|sound card index 0}}. Check sound cards index with "''pactl list cards short''" command.}}
 
{{Info|Example below is given for {{highlight|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
 
  {{Board$}} pacmd set-card-profile 0 output:analog-stereo+input:analog-stereo
  +
</div></div>
   
Launch audio record:
+
* '''Launch audio record :'''
 
  {{Board$}} arecord -d 10 /tmp/rec.wav
 
  {{Board$}} arecord -d 10 /tmp/rec.wav
   
Line 37: Line 45:
 
{{Warning|The support of digital microphone input is board dependent. Please, check available inputs with "''arecord -l''" command.}}
 
{{Warning|The support of digital microphone input is board dependent. Please, check available inputs with "''arecord -l''" command.}}
   
* '''Record from ALSA device'''
+
==== Record from ALSA device ====
Launch audio record from 'record_dfsdm0' ALSA device:
+
Launch 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.}}
 
{{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
 
  {{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 ====
  +
Launch 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 (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 system.pa configuration file.}}
  +
  +
{{Board$}} pacmd set-default-source dmic1_input
  +
  +
* '''Launch audio record :'''
  +
{{Board$}} arecord -r 48000 -f S32_LE -c 2 -d 10 /tmp/rec.wav
   
 
=== Audio record from S/PDIF input ===
 
=== Audio record from S/PDIF input ===
 
{{Warning|The support of S/PDIF input is board dependent. Please, check available inputs with "''arecord -l''" command.}}
 
{{Warning|The support of S/PDIF input is board dependent. Please, check available inputs with "''arecord -l''" command.}}
   
* '''Record from ALSA device'''
+
==== Record from ALSA device ====
 
Launch audio record from 'record_spdif' ALSA device:
 
Launch audio record from 'record_spdif' ALSA device:
 
{{Info|'record_spdif' is an alias defined in /etc/asound.conf, for S/PDIF input 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 launching the record command. The record rate must be set according to S/PDIF signal sampling rate.}}
 
{{Info|A S/PDIF signal must be available on S/PDIF RCA input connector before launching 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
 
  {{Board$}} arecord -D record_spdif -f S32_LE -c 2 -r 48000 -d 10 /tmp/rec.wav
  +
  +
==== Record via PulseAudio (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 system.pa configuration file.}}
  +
  +
{{Board$}} pacmd set-default-source iec958_input
  +
  +
* '''Launch audio record :'''
  +
{{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>

Attachments

Discussions