1
+ import csv
1
2
import os
2
3
import re
3
4
import xml .etree .ElementTree as ET
4
5
from glob import glob
5
6
from pathlib import Path
6
7
from typing import List
7
8
8
- import pandas as pd
9
9
from tqdm import tqdm
10
10
11
11
########################
@@ -25,25 +25,27 @@ def cml_tts(root_path, meta_file, ignored_speakers=None):
25
25
if len (line .split ("|" )) != num_cols :
26
26
print (f" > Missing column in line { idx + 1 } -> { line .strip ()} " )
27
27
# load metadata
28
- metadata = pd .read_csv (os .path .join (root_path , meta_file ), sep = "|" )
29
- assert all (x in metadata .columns for x in ["wav_filename" , "transcript" ])
30
- client_id = None if "client_id" in metadata .columns else "default"
31
- emotion_name = None if "emotion_name" in metadata .columns else "neutral"
28
+ with open (Path (root_path ) / meta_file , newline = "" , encoding = "utf-8" ) as f :
29
+ reader = csv .DictReader (f , delimiter = "|" )
30
+ metadata = list (reader )
31
+ assert all (x in metadata [0 ] for x in ["wav_filename" , "transcript" ])
32
+ client_id = None if "client_id" in metadata [0 ] else "default"
33
+ emotion_name = None if "emotion_name" in metadata [0 ] else "neutral"
32
34
items = []
33
35
not_found_counter = 0
34
- for row in metadata . itertuples () :
35
- if client_id is None and ignored_speakers is not None and row . client_id in ignored_speakers :
36
+ for row in metadata :
37
+ if client_id is None and ignored_speakers is not None and row [ " client_id" ] in ignored_speakers :
36
38
continue
37
- audio_path = os .path .join (root_path , row . wav_filename )
39
+ audio_path = os .path .join (root_path , row [ " wav_filename" ] )
38
40
if not os .path .exists (audio_path ):
39
41
not_found_counter += 1
40
42
continue
41
43
items .append (
42
44
{
43
- "text" : row . transcript ,
45
+ "text" : row [ " transcript" ] ,
44
46
"audio_file" : audio_path ,
45
- "speaker_name" : client_id if client_id is not None else row . client_id ,
46
- "emotion_name" : emotion_name if emotion_name is not None else row . emotion_name ,
47
+ "speaker_name" : client_id if client_id is not None else row [ " client_id" ] ,
48
+ "emotion_name" : emotion_name if emotion_name is not None else row [ " emotion_name" ] ,
47
49
"root_path" : root_path ,
48
50
}
49
51
)
@@ -63,25 +65,27 @@ def coqui(root_path, meta_file, ignored_speakers=None):
63
65
if len (line .split ("|" )) != num_cols :
64
66
print (f" > Missing column in line { idx + 1 } -> { line .strip ()} " )
65
67
# load metadata
66
- metadata = pd .read_csv (os .path .join (root_path , meta_file ), sep = "|" )
67
- assert all (x in metadata .columns for x in ["audio_file" , "text" ])
68
- speaker_name = None if "speaker_name" in metadata .columns else "coqui"
69
- emotion_name = None if "emotion_name" in metadata .columns else "neutral"
68
+ with open (Path (root_path ) / meta_file , newline = "" , encoding = "utf-8" ) as f :
69
+ reader = csv .DictReader (f , delimiter = "|" )
70
+ metadata = list (reader )
71
+ assert all (x in metadata [0 ] for x in ["audio_file" , "text" ])
72
+ speaker_name = None if "speaker_name" in metadata [0 ] else "coqui"
73
+ emotion_name = None if "emotion_name" in metadata [0 ] else "neutral"
70
74
items = []
71
75
not_found_counter = 0
72
- for row in metadata . itertuples () :
73
- if speaker_name is None and ignored_speakers is not None and row . speaker_name in ignored_speakers :
76
+ for row in metadata :
77
+ if speaker_name is None and ignored_speakers is not None and row [ " speaker_name" ] in ignored_speakers :
74
78
continue
75
- audio_path = os .path .join (root_path , row . audio_file )
79
+ audio_path = os .path .join (root_path , row [ " audio_file" ] )
76
80
if not os .path .exists (audio_path ):
77
81
not_found_counter += 1
78
82
continue
79
83
items .append (
80
84
{
81
- "text" : row . text ,
85
+ "text" : row [ " text" ] ,
82
86
"audio_file" : audio_path ,
83
- "speaker_name" : speaker_name if speaker_name is not None else row . speaker_name ,
84
- "emotion_name" : emotion_name if emotion_name is not None else row . emotion_name ,
87
+ "speaker_name" : speaker_name if speaker_name is not None else row [ " speaker_name" ] ,
88
+ "emotion_name" : emotion_name if emotion_name is not None else row [ " emotion_name" ] ,
85
89
"root_path" : root_path ,
86
90
}
87
91
)
0 commit comments