腳本以下:工具
#!/bin/sh filename=$1 # 腳本參數:保存的音頻文件名 monitor=$(pacmd list | grep -e 'name:.*.monitor' | sed -e 's/\s*name: <//' | sed -e 's/>//') # 麥克風 arecord -f S16_LE -c 2 -r 44100 $filename.1.wav & ARECORD_PID=$! # 回放 parec -d $monitor | sox -t raw -r 44100 -e signed-integer -L -b 16 -c 2 - $filename.2.wav & PAREC_PID=$! echo "recording... (press CTRL+C to end recording)" BEGIN_TIME=$(date +%s) END_RECORD=0 # 混音 trap "echo 'mixing audio'; kill $ARECORD_PID; kill $PAREC_PID; sleep 1; sox -m $filename.1.wav $filename.2.wav -c 1 $filename.wav; exit" 2 while [ $END_RECORD -le 1 ] do COST_TIME=`expr $(date +%s) - $BEGIN_TIME` printf "$COST_TIME\r" sleep 1 done