• 「Linux」Linux下根据CET听力文件关键字和lcr时间对mp3进行剪辑分割


    1. 脚本内容:

    #!/bin/bash
    # Author: linkscue
    # Version: 0.2
    # Usage: ./mp3cutsh $input $output
    # To use before: sudo apt-get install poc-streamer

    if [[ $# != 2 ]]; then #statements echo 'mp3cutsh $input $output' exit 1 fi # 相关的变量,截取文件名、输出路径 input=${1%.*} output=${2%/} input_mp3=${input}.mp3 input_lrc=${input}.lrc #创建目录 mkdir $output &> /dev/null # 截取conversation短对话11~18题 keywork1="[bB]egin [wW]ith [tT]he" keywork2="[cC]onversation [oO]ne" infomation="8 short conversations" part_name="conversation" output_base=$output/$part_name # 相关计算 start=$(sed -n "/$keywork1/p" $input_lrc | awk '{print substr($0,2,8)}' -) end=$(sed -n "/$keywork2/p" $input_lrc | awk '{print substr($0,2,8)}' -) start_t=$(echo $start | sed -e 's/\./+/' - )0 end_t=$(echo $end | sed -e 's/\./+/' - )0 if [[ $start ]]; then #只在非空时执行操作 #statements echo "I: Cutting from [$start] to [$end] -> $output_base.mp3" mp3cut -o $output_base.mp3 -t $start_t-$end_t $input_mp3 &> /dev/null sed -n "/$start/,/$end/p" $input_lrc > ${output_base}.lrc fi # 截取conversation 1 keywork1="[cC]onversation [oO]ne" keywork2="[cC]onversation [tT]wo" infomation="conversation one" part_name="conversation1" output_base=$output/$part_name # 相关计算 start=$(sed -n "/$keywork1/p" $input_lrc | awk '{print substr($0,2,8)}' -) end=$(sed -n "/$keywork2/p" $input_lrc | awk '{print substr($0,2,8)}' -) start_t=$(echo $start | sed -e 's/\./+/' - )0 end_t=$(echo $end | sed -e 's/\./+/' - )0 if [[ $start ]]; then #只在非空时执行操作 #statements echo "I: Cutting from [$start] to [$end] -> $output_base.mp3" mp3cut -o $output_base.mp3 -t $start_t-$end_t $input_mp3 &> /dev/null sed -n "/$start/,/$end/p" $input_lrc > ${output_base}.lrc fi # 截取conversation 2 keywork1="[cC]onversation [tT]wo" keywork2="[sS]ection [bB]" infomation="conversation two" part_name="conversation2" output_base=$output/$part_name # 相关计算 start=$(sed -n "/$keywork1/p" $input_lrc | awk '{print substr($0,2,8)}' -) end=$(sed -n "/$keywork2/p" $input_lrc | awk '{print substr($0,2,8)}' -) start_t=$(echo $start | sed -e 's/\./+/' - )0 end_t=$(echo $end | sed -e 's/\./+/' - )0 if [[ $start ]]; then #只在非空时执行操作 #statements echo "I: Cutting from [$start] to [$end] -> $output_base.mp3" mp3cut -o $output_base.mp3 -t $start_t-$end_t $input_mp3 &> /dev/null sed -n "/$start/,/$end/p" $input_lrc > ${output_base}.lrc fi # 截取passage 1 keywork1="[pP]assage [oO]ne" keywork2="[pP]assage [tT]wo" infomation="passage one" part_name="passage1" output_base=$output/$part_name # 相关计算 start=$(sed -n "/$keywork1/p" $input_lrc | awk '{print substr($0,2,8)}' -) end=$(sed -n "/$keywork2/p" $input_lrc | awk '{print substr($0,2,8)}' -) start_t=$(echo $start | sed -e 's/\./+/' - )0 end_t=$(echo $end | sed -e 's/\./+/' - )0 if [[ $start ]]; then #只在非空时执行操作 #statements echo "I: Cutting from [$start] to [$end] -> $output_base.mp3" mp3cut -o $output_base.mp3 -t $start_t-$end_t $input_mp3 &> /dev/null sed -n "/$start/,/$end/p" $input_lrc > ${output_base}.lrc fi # 截取passage 2 keywork1="[pP]assage [tT]wo" keywork2="Passage [tT]hree" infomation="passage two" part_name="passage2" output_base=$output/$part_name # 相关计算 start=$(sed -n "/$keywork1/p" $input_lrc | awk '{print substr($0,2,8)}' -) end=$(sed -n "/$keywork2/p" $input_lrc | awk '{print substr($0,2,8)}' -) start_t=$(echo $start | sed -e 's/\./+/' - )0 end_t=$(echo $end | sed -e 's/\./+/' - )0 if [[ $start ]]; then #只在非空时执行操作 #statements echo "I: Cutting from [$start] to [$end] -> $output_base.mp3" mp3cut -o $output_base.mp3 -t $start_t-$end_t $input_mp3 &> /dev/null sed -n "/$start/,/$end/p" $input_lrc > ${output_base}.lrc fi # 截取passage 3 keywork1="Passage [tT]hree" keywork2="[sS]ection [cC]" infomation="passage three" part_name="passage3" output_base=$output/$part_name # 相关计算 start=$(sed -n "/$keywork1/p" $input_lrc | awk '{print substr($0,2,8)}' -) end=$(sed -n "/$keywork2/p" $input_lrc | awk '{print substr($0,2,8)}' -) start_t=$(echo $start | sed -e 's/\./+/' - )0 end_t=$(echo $end | sed -e 's/\./+/' - )0 if [[ $start ]]; then #只在非空时执行操作 #statements echo "I: Cutting from [$start] to [$end] -> $output_base.mp3" mp3cut -o $output_base.mp3 -t $start_t-$end_t $input_mp3 &> /dev/null sed -n "/$start/,/$end/p" $input_lrc > ${output_base}.lrc fi # 截取听写部分 keywork1="[nN]ow [lL]isten [tT]o [tT]he [pP]assage" keywork2="[tT]his [iI]s [tT]he [eE]nd" infomation="Section C" part_name="sectionc" output_base=$output/$part_name # 相关计算 start=$(sed -n "/$keywork1/p" $input_lrc | awk '{print substr($0,2,8)}' -) end=$(sed -n "/$keywork2/p" $input_lrc | awk '{print substr($0,2,8)}' -) start_t=$(echo $start | sed -e 's/\./+/' - )0 end_t=$(echo $end | sed -e 's/\./+/' - )0 if [[ $start ]]; then #只在非空时执行操作 #statements echo "I: Cutting from [$start] to [$end] -> $output_base.mp3" mp3cut -o $output_base.mp3 -t $start_t-$end_t $input_mp3 &> /dev/null sed -n "/$start/,/$end/p" $input_lrc > ${output_base}.lrc fi echo "I: All Done!" # this is the old version code #output_mp3=$1.mp3 #output_lrc=$1.lrc #start=$(echo $2 | sed -e 's/\./+/' - )0 #end=$(echo $3 | sed -e 's/\./+/' - )0 #input_mp3=$4.mp3 #input_lrc=$4.lrc #mp3cut -o $output_mp3 -t $start-$end $input_mp3 #sed -n "/$2/,/$3/p" $input_lrc > $output_lrc # 转换文本的编码格式 #iconv -f gb18030 -t utf-8 $output_lrc $output_lrc # cat $output_lrc

    2. 输出结果展示

    scue@Link:cet$ ./mp3cutsh 2012年6月.mp3 cet2012
    I: Cutting from [02:51.74] to [07:37.54] -> cet2012/conversation.mp3
    I: Cutting from [07:37.54] to [10:39.12] -> cet2012/conversation1.mp3
    I: Cutting from [10:39.12] to [13:35.27] -> cet2012/conversation2.mp3
    I: Cutting from [14:08.62] to [16:54.10] -> cet2012/passage1.mp3
    I: Cutting from [16:54.10] to [19:33.92] -> cet2012/passage2.mp3
    I: Cutting from [19:33.92] to [22:57.88] -> cet2012/passage3.mp3
    I: Cutting from [23:50.05] to [32:27.48] -> cet2012/sectionc.mp3
    I: All Done
    ------------
    微博:http://weibo.com/scue
    Github:http://github.com/scue
  • 相关阅读:
    Kalman Filters
    基于堆栈实现计算器
    Centos 7创建软连接,硬连接的方法
    Centos 7下对磁盘的分区格式化挂载交换空间的建立
    文件的归档打包压缩解压缩
    文件目录操作命令及权限的修改设置
    用户添加修改文件的操作
    linux今日学习命令 who
    CentOS安装流程
    计算机网络基础
  • 原文地址:https://www.cnblogs.com/scue/p/2828679.html
Copyright © 2020-2023  润新知