如何使用sox正确地重新采样和连接wav文件?

时间:2017-02-27 12:19:02

标签: python python-3.x audio concatenation sox

代码正在运行,但它提供了多行输出,而我只需要一条水平线

当前输出格式 -

sox home / randy / mechanical / wav / ttsmf_007 / ttsmf_007_103 .wav -r 12000 -t raw / home / randy / mechanical / raw / ttsmf_007 / ttsmf_007_103 .RAW

sox home / randy / mechanical / wav / ttsmf_007 / ttsmf_007_104 .wav -r 12000 -t raw / home / randy / mechanical / raw / ttsmf_007 / ttsmf_007_104 .RAW

.....

sox home / randy / mechanical / wav / ttsmf_007 / ttomf_007_189 .wav -r 12000 -t raw / home / randy / mechanical / raw / ttsmf_007 / ttomf_007_189 .RAW

所需的输出格式 -

sox home / randy / mechanical / wav / ttsmf_007 / ttsmf_007_103.wav .......... ttsmf_007_103.raw

sox home / randy / mechanical / wav / ttsmf_007 / ttsmf_007_104.wav .......... ttsmf_007_104.raw

............................................... .................................

sox home / randy / mechanical / wav / ttomf_007 / ttomf_007_189.wav .......... ttomf_007_189.raw

---------------------------- CODE ------------------ -----------------------------

#!/usr/bin/env python

fo= open("ml.ctl","r")
for line in fo.readlines():
    a1 = line[0:]
    y = "sox"+ " " + "/home/randy/mechanical/wav/"+ str(a1)+".wav"+ " " + "-r"+ " " + "12000"+ " " + "-t" + " " + "raw" +"/home/randy/mechanical/raw + str(a1) + ".raw"
    print(y)
fo.close()
fo= open("newmlt.ctl","w")
fo.close()

1 个答案:

答案 0 :(得分:0)

使用正则表达式删除回车:

#!/usr/bin/env python

import re

fo= open("ml.ctl","r")
for line in fo.readlines():
    a1 = line[0:]
    y = "sox"+ " " + "/home/randy/mechanical/wav/"+ str(a1)+".wav"+ " " + "-r"+ " " + "12000"+ " " + "-t" + " " + "raw" +"/home/randy/mechanical/raw + str(a1) + ".raw"
    y = re.sub("\n", '', y)
    print(y)
fo.close()
fo= open("newmlt.ctl","w")
fo.close()

无论如何我认为问题出在原始文件ml.ctl或读取它的方式