Skip to content

Commit f24f7c1

Browse files
authored
Merge pull request #3 from eginhard/remove-pandas
Remove pandas
2 parents 24298da + e4b1b0f commit f24f7c1

File tree

4 files changed

+34
-28
lines changed

4 files changed

+34
-28
lines changed

TTS/encoder/utils/prepare_voxceleb.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
# pylint: disable=too-many-locals, too-many-statements, too-many-arguments, too-many-instance-attributes
2020
""" voxceleb 1 & 2 """
2121

22+
import csv
2223
import hashlib
2324
import os
2425
import subprocess
2526
import sys
2627
import zipfile
2728

28-
import pandas
2929
import soundfile as sf
3030
from absl import logging
3131

@@ -185,8 +185,11 @@ def convert_audio_and_make_label(input_dir, subset, output_dir, output_file):
185185
# Write to CSV file which contains four columns:
186186
# "wav_filename", "wav_length_ms", "speaker_id", "speaker_name".
187187
csv_file_path = os.path.join(output_dir, output_file)
188-
df = pandas.DataFrame(data=files, columns=["wav_filename", "wav_length_ms", "speaker_id", "speaker_name"])
189-
df.to_csv(csv_file_path, index=False, sep="\t")
188+
with open(csv_file_path, "w", newline="", encoding="utf-8") as f:
189+
writer = csv.writer(f, delimiter="\t")
190+
writer.writerow(["wav_filename", "wav_length_ms", "speaker_id", "speaker_name"])
191+
for wav_file in files:
192+
writer.writerow(wav_file)
190193
logging.info("Successfully generated csv file {}".format(csv_file_path))
191194

192195

TTS/tts/datasets/formatters.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
import csv
12
import os
23
import re
34
import xml.etree.ElementTree as ET
45
from glob import glob
56
from pathlib import Path
67
from typing import List
78

8-
import pandas as pd
99
from tqdm import tqdm
1010

1111
########################
@@ -25,25 +25,27 @@ def cml_tts(root_path, meta_file, ignored_speakers=None):
2525
if len(line.split("|")) != num_cols:
2626
print(f" > Missing column in line {idx + 1} -> {line.strip()}")
2727
# 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"
3234
items = []
3335
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:
3638
continue
37-
audio_path = os.path.join(root_path, row.wav_filename)
39+
audio_path = os.path.join(root_path, row["wav_filename"])
3840
if not os.path.exists(audio_path):
3941
not_found_counter += 1
4042
continue
4143
items.append(
4244
{
43-
"text": row.transcript,
45+
"text": row["transcript"],
4446
"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"],
4749
"root_path": root_path,
4850
}
4951
)
@@ -63,25 +65,27 @@ def coqui(root_path, meta_file, ignored_speakers=None):
6365
if len(line.split("|")) != num_cols:
6466
print(f" > Missing column in line {idx + 1} -> {line.strip()}")
6567
# 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"
7074
items = []
7175
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:
7478
continue
75-
audio_path = os.path.join(root_path, row.audio_file)
79+
audio_path = os.path.join(root_path, row["audio_file"])
7680
if not os.path.exists(audio_path):
7781
not_found_counter += 1
7882
continue
7983
items.append(
8084
{
81-
"text": row.text,
85+
"text": row["text"],
8286
"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"],
8589
"root_path": root_path,
8690
}
8791
)

requirements.notebooks.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
bokeh==1.4.0
1+
bokeh==1.4.0
2+
pandas>=1.4,<2.0

requirements.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ torchaudio
88
soundfile>=0.12.0
99
librosa>=0.10.0
1010
scikit-learn>=1.3.0
11-
numba==0.55.1;python_version<"3.9"
1211
numba>=0.57.0;python_version>="3.9"
1312
inflect>=5.6.0
1413
tqdm>=4.64.1
@@ -24,7 +23,6 @@ flask>=2.0.1
2423
pysbd>=0.3.4
2524
# deps for notebooks
2625
umap-learn>=0.5.1
27-
pandas>=1.4,<2.0
2826
# deps for training
2927
matplotlib>=3.7.0
3028
# coqui stack
@@ -54,4 +52,4 @@ encodec>=0.1.1
5452
# deps for XTTS
5553
unidecode>=1.3.2
5654
num2words
57-
spacy[ja]>=3
55+
spacy[ja]>=3

0 commit comments

Comments
 (0)