Skip to content

Commit

Permalink
test(compute_statistics): convert to python
Browse files Browse the repository at this point in the history
  • Loading branch information
eginhard committed Dec 16, 2024
1 parent 267c7aa commit 2370b7b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
16 changes: 11 additions & 5 deletions TTS/bin/compute_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import glob
import logging
import os
import sys
from typing import Optional

import numpy as np
from tqdm import tqdm
Expand All @@ -16,10 +18,7 @@
from TTS.utils.generic_utils import ConsoleFormatter, setup_logger


def main():
"""Run preprocessing process."""
setup_logger("TTS", level=logging.INFO, screen=True, formatter=ConsoleFormatter())

def parse_args(arg_list: Optional[list[str]]) -> tuple[argparse.Namespace, list[str]]:
parser = argparse.ArgumentParser(description="Compute mean and variance of spectrogtram features.")
parser.add_argument("config_path", type=str, help="TTS config file path to define audio processin parameters.")
parser.add_argument("out_path", type=str, help="save path (directory and filename).")
Expand All @@ -29,7 +28,13 @@ def main():
required=False,
help="folder including the target set of wavs overriding dataset config.",
)
args, overrides = parser.parse_known_args()
return parser.parse_known_args(arg_list)


def main(arg_list: Optional[list[str]] = None):
"""Run preprocessing process."""
setup_logger("TTS", level=logging.INFO, screen=True, formatter=ConsoleFormatter())
args, overrides = parse_args(arg_list)

CONFIG = load_config(args.config_path)
CONFIG.parse_known_args(overrides, relaxed_parser=True)
Expand Down Expand Up @@ -94,6 +99,7 @@ def main():
stats["audio_config"] = CONFIG.audio.to_dict()
np.save(output_file_path, stats, allow_pickle=True)
print(f" > stats saved to {output_file_path}")
sys.exit(0)


if __name__ == "__main__":
Expand Down
3 changes: 1 addition & 2 deletions run_bash_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ TF_CPP_MIN_LOG_LEVEL=3

# runtime bash based tests
# TODO: move these to python
./tests/bash_tests/test_demo_server.sh && \
./tests/bash_tests/test_compute_statistics.sh
./tests/bash_tests/test_demo_server.sh
10 changes: 10 additions & 0 deletions tests/aux_tests/test_compute_statistics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from pathlib import Path

from tests import get_tests_input_path, run_main
from TTS.bin.compute_statistics import main


def test_compute_statistics(tmp_path):
config_path = Path(get_tests_input_path()) / "test_glow_tts_config.json"
output_path = tmp_path / "scale_stats.npy"
run_main(main, ["--config_path", str(config_path), "--out_path", str(output_path)])
6 changes: 0 additions & 6 deletions tests/bash_tests/test_compute_statistics.sh

This file was deleted.

0 comments on commit 2370b7b

Please sign in to comment.