gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 23:38:12 27 4
gpt4 key购买 nike

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

当前输出格式

袜家/兰迪/机械/波浪/ ttsmf_007 / ttsmf_007_103
.wav -r 12000 -t raw / home / randy / mechanical / raw / ttsmf_007 / ttsmf_007_103
。生的

袜家/兰迪/机械/波浪/ ttsmf_007 / ttsmf_007_104
.wav -r 12000 -t raw / home / randy / mechanical / raw / ttsmf_007 / ttsmf_007_104
。生的

.....

袜家/兰迪/机械/ wav / ttsmf_007 / ttomf_007_189
.wav -r 12000 -t raw / home / randy / mechanical / raw / ttsmf_007 / ttomf_007_189
。生的

所需的输出格式

袜家/兰迪/机械/wav/ttsmf_007/ttsmf_007_103.wav..........tts​​mf_007_103.raw

袜家/兰迪/机械/wav/ttsmf_007/ttsmf_007_104.wav..........tts​​mf_007_104.raw

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

袜家/兰迪/机械/波浪/ttomf_007/ttomf_007_189.wav..........ttomf_007_189.raw

- - - - - - - - - - - - - - 码 - - - - - - - - - - - --------------------------

#!/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()

最佳答案

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

#!/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或读取它的方式中

关于python - 如何使用sox重新采样和正确连接wav文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42485675/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com