sox和shell结合多通道wav文件中抽取特定通道重新排序的脚本

#########################################################################

# File Name: Fetch5ch.sh

# Function :extract 6 1 2 8 channel as a new file from 8channel wave file

# Created Time: Thu 22 Mar 2018 03:27:02 PM CST

#########################################################################

#!/bin/bash

ARGS=2;

E_BADQUIT=127;

E_BADPARAM=65;

if [[ $# -ne ${ARGS} ]];then

        echo -e "Usage: \n\t `(basename $0 .sh)` wave-file-directory out-file-directory"

        exit ${E_BADPARAM}

fi

wave_dir=$1;

out_dir=$2;

if [[ ! -d ${wave_dir} ]];then

        echo "Error : can not find path ${wave_dir}"

        exit ${E_BADPARAM}

fi

if [[ ! -d ${out_dir} ]];then

        echo "Error : cannot find out directory."

        exit ${E_BADPARMA}

else

        is_empty=`ls ${out_dir} | wc -l`

        if [[ ${is_empty} -ne 0 ]];then

                echo "Warning : ${out_dir} is not empty"

        fi

fi

find ${wave_dir}/*.wav > tmp

cat tmp | awk 'BEGIN{FS="/"}{print $NF}' > tmp1

rm tmp

# 检测输入的wave数据的通道数目,本脚本设定的是8

function CheckChannel()

{

wave=$1;

num_ch=`soxi ${wave} | grep -w "Channels" | awk 'BEGIN{FS=":"}{print $NF}'`

if [[ ${num_ch} -lt 8  ]];then

        return 1;

else

        return 0;

fi

}

# 本脚本从8通道数据抽取5个通道,对5个通道重新排列

ch1=6;

ch2=1;

ch3=2;

ch4=8;

ch5=7;

while read line;do

        name="`echo ${line%%.*}`_valid14.wav"

        CheckChannel "${wave_dir}/${line}"

        if [[ `echo $?` -ne 0 ]];then

                echo "Error : channels of ${wave_dir}/${line} is less than 8"

                exit ${E_BADQUIT}

        fi

        echo $wave_dir/$line

        if [[ -f ${out_dir}/${name} ]];then

                echo "Error : ${out_dir} have existed ${name}"

                exit ${E_BADPARAM}

        fi

        echo $wave_dir/$line

        sox ${wave_dir}/${line} ${out_dir}/${name} remix ${ch1} ${ch2} ${ch3} ${ch4} ${ch5}

done < tmp1

rm tmp1

exit $?

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 1.创建文件夹 !/bin/sh mkdir -m 777 "%%1" 2.创建文件 !/bin/sh touch...
    BigJeffWang阅读 10,508评论 3 53
  • 为何叫做 shell ? shell prompt(PS1) 与 Carriage Return(CR) 的关系?...
    Zero___阅读 3,344评论 3 49
  • .bat脚本基本命令语法 目录 批处理的常见命令(未列举的命令还比较多,请查阅帮助信息) 1、REM 和 :: 2...
    庆庆庆庆庆阅读 8,542评论 1 19
  • 个人学习批处理的初衷来源于实际工作;在某个迭代版本有个BS(安卓手游模拟器)大需求,从而在测试过程中就重复涉及到...
    Luckykailiu阅读 5,001评论 0 11
  • 资料一: 化敌为友 盟友 沉没成本 若能将一个反对者转变为支持者,在这个过程中你会将自己的方案更加完善,认识更加深...
    一粟于海阅读 241评论 2 2

友情链接更多精彩内容