【语音转换:客观评价MCD如何计算?】

计算MCD值

写在前面:感谢github作者Lukelluke,更为详细的参考可点击:Lukelluke

  1. 准备mcdmerlin-master

  2. 准备源语音和转录的语音。 创建两个文件夹,分别存放原语音和转录的语音。源语音和转录的语音要一一对应,文件名一定要相同,否则无法计算。

    mkdir org
    mkdir convert
    
  3. 获取mgc,bap,lf0文件。

     cd merlin-master/egs/voice_conversion/s1/
     ./01_setup.sh sperakera speakerb
    

    sperakera、speakerb会建在database文件夹下面,将org中的源语音文件和convert中的转换的语音分别拷贝到sperakera和speakerb中, 然后执行以下命令:

    ./02_....sh database/sperakera database/sperakera_extract
    ./02_....sh database/sperakerb database/sperakerb_extract
    

    将会把.mgc, .bap, .lf0 三类文件分别提取到sperakera_extract和sperakerb_extract中。
    提取完成后:
    (1)将源语音(也就是sperakera_extract文件夹下)的.mgc文件复制到 mcd/test_data/ref-examples下,
    (2)将转录的语音(也就是sperakerb_extract文件夹下).mgc .bap .lf0三种类型的文件复制到mcd/test_data/synth-examples下

  4. 计算MCD
    将所有源语音和转录语音相互对应的文件名,写入到mcd/test_data/corpus.lst中。 然后执行命令:

    cat test_data/corpus.lst | xargs bin/dtw_synth test_data/ref-examples test_data/synth-examples out
    

    即可计算

corpus.lst文件参考示例:

	p229_p362_081
	p260_p343_386

只有文件名,不带后缀,且保证源文件和转录语音文件名相同

注: 如果报错,可以尝试修改mcd/bin/dtw_synth中import htk_io.vecseq as vsio的vecseq。ctrl点击进去修改即可

def readFile(self, vecSeqFile):
    """Reads a raw vector sequence file.
    
    The dtype of the returned numpy array is always the numpy default
    np.float, which may be 32-bit or 64-bit depending on architecture, etc.
    """
    Vec = np.fromfile(vecSeqFile, dtype=self.dtypeFile)
    lengthOfVec = len(Vec)
    misLenToPad = lengthOfVec % self.vecSize
    means = np.mean(Vec)

    for i in range(misLenToPad):
        Vec = np.insert(Vec, lengthOfVec, means)

    return np.reshape(
        Vec,
        (-1, self.vecSize)
    ).astype(np.float)

    # return np.reshape(
    #     np.fromfile(vecSeqFile, dtype=self.dtypeFile),
    #     (-1, self.vecSize)
    # ).astype(np.float)

根据转换的文件,复制多份对应的源文件,使其文件名对应

# python2
def mycopy3():
    org_path = "/mnt/hgfs/VmwareShare/mcd/org"
    opt4_path = "/mnt/hgfs/VmwareShare/mcd/test"
    opt4_outpath = "/mnt/hgfs/VmwareShare/mcd/test_output"

    for wav in os.listdir(org_path):
        name1 = wav
        # print name1
        for con_name in os.listdir(opt4_path):
            name2 = con_name.split('_')
            print name2
            name3 = name2[1].strip("C") + "_" + name2[2] + ".wav"
            print name3
            if name3 == name1:
                shutil.copy(os.path.join(org_path, name1), os.path.join(opt4_outpath, con_name))

列出不带.wav后缀的文件名

# python2
def list_filename2():
    org_path = "/home/ubuntu/Downloads/merlin-master/egs/voice_conversion/s1/database/speakerb"
    for filename in os.listdir(org_path):
        print filename.strip(".wav")

猜你喜欢

转载自blog.csdn.net/weixin_42538665/article/details/127749829