简体   繁体   English

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

[英]Capture/Record Audio in Linux for Milliseconds

arecord -d 10 sample.wav

Here, this command will record sample.wav as a 10 second wave file.在这里,此命令会将 sample.wav 记录为 10 秒的波形文件。

From,从,

Here, in arecord, for duration (parameter -d) only second can be used.在这里,在 arecord 中,对于持续时间(参数 -d),只能使用秒。

But for my project, I need to record for 600 milliseconds or 2700 milliseconds.但是对于我的项目,我需要记录 600 毫秒或 2700 毫秒。 Here, is there any way to use millisecond or microsecond?在这里,有没有办法使用毫秒或微秒?

Do I need to modify ALSA code to achieve this?我是否需要修改 ALSA 代码来实现这一点?

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

You can use the code i made.您可以使用我制作的代码。 It's a C program to use alsa simply.这是一个简单地使用 alsa 的 C 程序。

https://github.com/Waxo/ALSA_encapsulation https://github.com/Waxo/ALSA_encapsulation

With ffmpeg , here to record a 5ms wav sample:使用ffmpeg ,这里记录一个 5ms 的 wav 样本:

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

The sound card list for the -i parameter: -i参数的声卡列表:

arecord -l

Bonus!奖金! To analyse the sample peaks:分析样品峰:

sox -S volt.wav -n stats

You can compile and use the ALSACaptureSplitter application, specifying the duration as a floating point number - which will allow you to specify any accuracy you want.您可以编译和使用 ALSACaptureSplitter 应用程序,将持续时间指定为浮点数 - 这将允许您指定所需的任何精度。 For example :例如 :

ALSACaptureSplitter -t 0.6 /tmp/test wav

This command will save audio 600 ms of audio to individual files in the /tmp directory.此命令会将音频 600 毫秒的音频保存到 /tmp 目录中的各个文件中。

You can build the application for your system using this email as a guide.您可以使用此电子邮件作为指南为您的系统构建应用程序。

Here is the help output from the ALSACaptureSplitter command :这是 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