有可能用bash吗?一些沿着以下方向的东西:
#!/bin/bash# audio devicedevice=/dev/audio-line-in# below this threshold audio will not be recorded.noise_threshold=10# folder where recordings are storedstorage_folder=~/recordings# run indefenitly,until Ctrl-C is pressedwhile true; do # noise_level() represents a function to determine # the noise level from device if noise_level( $device ) > $noise_threshold; then # stream from device to file,can be encoded to mp3 later. cat $device > $storage_folder/$(date +%FT%T).raw fi;done;
编辑:我想从这个程序获得的流程是
a. when noise > threshold,start recording b. stop recording when noise < threshold for 10 seconds c. save recorded pIEce to separate file解决方法 SoX是瑞士军刀的声音处理.您可以利用它来分析录音.以下解决方案的唯一缺点是:
>您需要将录音分割成固定大小的块
>您可能会丢失录音时间(由于杀死/分析/重新启动录音)
因此,进一步的改进可能是分析异步,尽管这将使工作复杂化.
#!/bin/bash record_interval=5noise_threshold=3storage_folder=~/recordingsexec 2>/dev/null # no default error outputwhile true; do rec out.wav & sleep $record_interval kill -KILL %1 max_level="$(sox out.wav -n stats -s 16 2>&1|awk '/^Max\ level/ {print int()}')" if [ $max_level -gt $noise_threshold ];then mv out.wav ${storage_folder}/recording-$(date +%FT%T).wav; else rm out.wav fidone
更新:
以下解决方案使用fifo作为rec的输出.通过在这个管道上使用拆分来获取块,应该没有丢失录音时间:
#!/bin/bash noise_threshold=3storage_folder=~/recordingsraw_folder=~/recordings/tmpsplit_folder=~/recordings/splitsox_raw_options="-t raw -r 48k -e signed -b 16"split_size=1048576 # 1Mmkdir -p ${raw_folder} ${split_folder}test -a ${raw_folder}/in.raw || mkfifo ${raw_folder}/in.raw# start recording and spliting in backgroundrec ${sox_raw_options} - >${raw_folder}/in.raw 2>/dev/null &split -b ${split_size} - <${raw_folder}/in.raw ${split_folder}/pIEce &while true; do # check each finished raw file for raw in $(find ${split_folder} -size ${split_size}c);do max_level="$(sox $sox_raw_options ${raw} -n stats -s 16 2>&1|awk '/^Max\ level/ {print int()}')" if [ $max_level -gt $noise_threshold ];then sox ${sox_raw_options} ${raw} ${storage_folder}/recording-$(date +%FT%T).wav; fi rm ${raw} done sleep 1done1总结
以上是内存溢出为你收集整理的linux – 监听音频线全部内容,希望文章能够帮你解决linux – 监听音频线所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)