python2根据索引表查找相应的录音片段拼接录音
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python2根据索引表查找相应的录音片段拼接录音相关的知识,希望对你有一定的参考价值。
#encoding:utf-8?
import csv
import os
dataConvert = []
dataStitch? = []
voiceFrom = "/home/mylinux/dengcong/"
voiceTar =? "/home/mylinux/dengcong/tar/"
os.system("mkdir -p "+voiceTar)
csvStitch = open("/home/mylinux/dengcong/stitch.csv", "r")
readerStitch = csv.reader(csvStitch)
csvConvert = open("/home/mylinux/dengcong/convert.csv", "r")
readerConvert = csv.reader(csvConvert)
for item1 in readerConvert:
??? dataConvert.append(item1)
for item2 in readerStitch:
??? dataStitch.append(item2)
def onePis(tmpId):
??? dataArr = []
??? for line in dataStitch:
??????? i = cmp(tmpId,line[0].strip())
??????? #print(tmpId,line[0].strip(),i)
??????? if i == 0:
??????????? dataArr.append(line)
??? dataArr.sort(key=lambda x:x[2])
??? return dataArr;
for item in dataConvert:
??? orderArr = []
??? tmpStr = item[2]+"0"+item[3]
??? tmpStr = tmpStr.strip()
??? orderArr.append(tmpStr.strip())
??? #print(tmpStr)
??? xxx = onePis(tmpStr)
??? for line in xxx:
??????? orderArr.append(line[1].strip())
??? #print(orderArr)
??? ffmStr = "ffmpeg "
??? for one in orderArr:
??????? ffmStr = ffmStr + " -i " + voiceFrom + one +".wav"
??? ffmStr = ffmStr + " -filter_complex ‘"
??? count = 0
??? while count<len(orderArr):
??????? ffmStr = ffmStr + "["+ str(count)+":0]"
??????? count = count + 1
??? ffmStr = ffmStr + " concat=n=" + str(len(orderArr)) + ":v=0:a=1‘ " + voiceTar +? tmpStr + "done.wav"
??? #print(ffmStr)
??? os.system(ffmStr)
csvStitch.close()
csvConvert.close()
以上是关于python2根据索引表查找相应的录音片段拼接录音的主要内容,如果未能解决你的问题,请参考以下文章