網頁

2023年10月26日 星期四

Ubuntu 之 錄音 與 撥放, 使用 arecord aplay ffmpeg

列出錄音設備
$ arecord -l
**** List of CAPTURE Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: ALCS1200A Analog [ALCS1200A Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 2: ALCS1200A Alt Analog [ALCS1200A Alt Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
指定 card:0, device 0, 使用16000採樣,錄音10秒
$ arecord -Dhw:0,0 -d 10 -f cd -r 16000 -c 2 -t wav test.wav
Recording WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 16000 Hz, Stereo
Warning: rate is not accurate (requested = 16000Hz, got = 44100Hz)
         please, try the plug plugin 
$ arecord -D mono --device=hw:0,0 -d 10 -f cd -r 16000 -c 2 -t wav test.wav
Recording WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 16000 Hz, Stereo
Warning: rate is not accurate (requested = 16000Hz, got = 44100Hz)
         please, try the plug plugin 

列出播放設備
$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: ALCS1200A Analog [ALCS1200A Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 1: ALCS1200A Digital [ALCS1200A Digital]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
從錄音設備直接撥出
$ arecord -Dhw:0,0 -d 10 -f cd -r 16000 | aplay -Dhw:0,0 -r 16000
Recording WAVE 'stdin' : Signed 16 bit Little Endian, Rate 16000 Hz, Stereo
Warning: rate is not accurate (requested = 16000Hz, got = 44100Hz)
         please, try the plug plugin 
Playing WAVE 'stdin' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo


安裝 ffmpeg
$ sudo add-apt-repository ppa:savoury1/ffmpeg4  
$ sudo apt-cache policy ffmpeg  
$ sudo apt-get install ffmpeg  
$ ffmpeg -version  
$ sudo add-apt-repository --remove ppa:savoury1/ffmpeg4  

參考 https://ffmpeg.org/ffmpeg-devices.html
列出裝置
$ ffmpeg -devices
Devices:
 D. = Demuxing supported
 .E = Muxing supported
 --
 DE alsa            ALSA audio output
  E caca            caca (color ASCII art) output device
 DE fbdev           Linux framebuffer
 D  iec61883        libiec61883 (new DV1394) A/V input device
 D  jack            JACK Audio Connection Kit
 D  kmsgrab         KMS screen capture
 D  lavfi           Libavfilter virtual input device

$ cat /proc/asound/cards
 0 [PCH            ]: HDA-Intel - HDA Intel PCH
                      HDA Intel PCH at 0xa7230000 irq 148
 1 [NVidia         ]: HDA-Intel - HDA NVidia
                      HDA NVidia at 0xa5080000 irq 17

錄音
$ ffmpeg -f alsa -i hw:0 test.wav

沒有留言:

張貼留言