繁体   English   中英

在 Linux 中以毫秒为单位捕获/录制音频

[英]Capture/Record Audio in Linux for Milliseconds

arecord -d 10 sample.wav

在这里,此命令会将 sample.wav 记录为 10 秒的波形文件。

从,

在这里,在 arecord 中,对于持续时间(参数 -d),只能使用秒。

但是对于我的项目,我需要记录 600 毫秒或 2700 毫秒。 在这里,有没有办法使用毫秒或微秒?

我是否需要修改 ALSA 代码来实现这一点?

您需要更改arecord的源代码(alsa-utils包中的aplay.c )来更改timelimit变量的类型和解析。

您可以使用我制作的代码。 这是一个简单地使用 alsa 的 C 程序。

https://github.com/Waxo/ALSA_encapsulation

使用ffmpeg ,这里记录一个 5ms 的 wav 样本:

ffmpeg -y -loglevel panic -f alsa -ac 1 -ar 44100 -i hw:2 -t 0.05 volt.wav

-i参数的声卡列表:

arecord -l

奖金! 分析样品峰:

sox -S volt.wav -n stats

您可以编译和使用 ALSACaptureSplitter 应用程序,将持续时间指定为浮点数 - 这将允许您指定所需的任何精度。 例如 :

ALSACaptureSplitter -t 0.6 /tmp/test wav

此命令会将音频 600 毫秒的音频保存到 /tmp 目录中的各个文件中。

您可以使用此电子邮件作为指南为您的系统构建应用程序。

这是 ALSACaptureSplitter 命令的帮助输出:

ALSACaptureSplitter -h
ALSACaptureSplitter : An application to capture input and save to independent files.
Usage:
     ALSACaptureSplitter [options] outFileNamePrefix ext
     e.g. ALSACaptureSplitter [options] /tmp/out wav
     -D : The name of the device : (-D hw:0)
     -c : The number of channels to open, if the available number is less, then it is reduced to the available : (-c 2)
     -t : The duration to sample for : (-t 2.1)
     -r : The sample rate to use in Hz : (-r 48000)
AUDIO FILE FORMATS:The known output file extensions (output file formats) are the following :
8svx aif aifc aiff aiffc al amb amr-nb amr-wb anb au avr awb caf cdda cdr cvs cvsd cvu dat dvms f32 f4 f64 f8 fap flac fssd gsm gsrt hcom htk ima ircam la lpc lpc10 lu mat mat4 mat5 maud mp2 mp3 nist ogg paf prc pvf raw s1 s16 s2 s24 s3 s32 s4 s8 sb sd2 sds sf sl sln smp snd sndfile sndr sndt sou sox sph sw txw u1 u16 u2 u24 u3 u32 u4 u8 ub ul uw vms voc vorbis vox w64 wav wavpcm wv wve xa xi

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM