简体   繁体   中英

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.

From,

Here, in arecord, for duration (parameter -d) only second can be used.

But for my project, I need to record for 600 milliseconds or 2700 milliseconds. Here, is there any way to use millisecond or microsecond?

Do I need to modify ALSA code to achieve this?

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

You can use the code i made. It's a C program to use alsa simply.

https://github.com/Waxo/ALSA_encapsulation

With ffmpeg , here to record a 5ms wav sample:

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:

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

You can build the application for your system using this email as a guide.

Here is the help output from the ALSACaptureSplitter command :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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