簡體   English   中英

如何使用sox正確地重新采樣和連接wav文件?

[英]How to resample and concatenate properly the wav files using 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

- - - - - - - - - - - - - - 碼 - - - - - - - - - - - --------------------------

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM