File size: 971 Bytes
d47c0cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import wespeakerruntime as wespeaker
import os
import numpy as np
from tqdm import tqdm

inference = wespeaker.Inference(lang='chs')
wave_path = '/home/admin/yuanxin/3.tempData/FastSpeech2/raw_data/AISHELL3-Pro'

def main():
    with open('speaker_embedding.txt', 'w', encoding='utf-8') as f:
        speakers_path = os.listdir(wave_path)
        for speaker in tqdm(speakers_path):
            if speaker in ['cicely', 'xiaoyin']:
                continue
            s_list = os.listdir(os.path.join(wave_path, speaker))
            temp = np.zeros((1, 256))
            count = 0
            for s in tqdm(s_list):
                if '.wav' in s:
                    count += 1
                    temp += inference.extract_embedding_wav(os.path.join(wave_path, speaker, s))
                else:
                    continue
            f.write(speaker + "|" + str((temp / count).tolist()[0]) + '\n')

if __name__ == "__main__":
    main()