簡體   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