Slight refactor of scripts, cleaning

This commit is contained in:
Michael Hansen
2023-12-21 11:52:41 -06:00
parent 8b1a90099a
commit 3d1f4463cf
12 changed files with 35 additions and 60 deletions

View File

@@ -2,3 +2,6 @@
[mypy-onnxruntime.*]
ignore_missing_imports = True
[mypy-piper_phonemize.*]
ignore_missing_imports = True

View File

@@ -3,7 +3,7 @@ import logging
import wave
from dataclasses import dataclass
from pathlib import Path
from typing import Iterable, List, Optional, Union
from typing import Any, Dict, Iterable, List, Optional, Tuple, Union
import numpy as np
import onnxruntime
@@ -34,14 +34,23 @@ class PiperVoice:
with open(config_path, "r", encoding="utf-8") as config_file:
config_dict = json.load(config_file)
providers: List[Union[str, Tuple[str, Dict[str, Any]]]]
if use_cuda:
providers = [
(
"CUDAExecutionProvider",
{"cudnn_conv_algo_search": "HEURISTIC"},
)
]
else:
providers = ["CPUExecutionProvider"]
return PiperVoice(
config=PiperConfig.from_dict(config_dict),
session=onnxruntime.InferenceSession(
str(model_path),
sess_options=onnxruntime.SessionOptions(),
providers=["CPUExecutionProvider"]
if not use_cuda
else [("CUDAExecutionProvider", {"cudnn_conv_algo_search": "HEURISTIC"})],
providers=providers,
),
)

View File

@@ -1,7 +1,6 @@
[MESSAGES CONTROL]
disable=
format,
abstract-class-little-used,
abstract-method,
cyclic-import,
duplicate-code,
@@ -10,7 +9,6 @@ disable=
inconsistent-return-statements,
locally-disabled,
not-context-manager,
redefined-variable-type,
too-few-public-methods,
too-many-arguments,
too-many-branches,
@@ -27,7 +25,6 @@ disable=
too-many-nested-blocks,
invalid-name,
unused-import,
no-self-use,
fixme,
useless-super-delegation,
missing-module-docstring,

View File

@@ -1,7 +1,5 @@
black==22.3.0
coverage==5.0.4
flake8==3.7.9
mypy==0.910
pylint==2.10.2
pytest==5.4.1
pytest-cov==2.8.1
black==22.12.0
flake8==6.0.0
isort==5.11.3
mypy==0.991
pylint==2.15.9

View File

@@ -0,0 +1 @@
onnxruntime-gpu>=1.11.0,<2

12
src/python_run/script/piper Executable file
View File

@@ -0,0 +1,12 @@
#!/usr/bin/env python3
import sys
import subprocess
import venv
from pathlib import Path
_DIR = Path(__file__).parent
_PROGRAM_DIR = _DIR.parent
_VENV_DIR = _PROGRAM_DIR / ".venv"
context = venv.EnvBuilder().ensure_directories(_VENV_DIR)
subprocess.check_call([context.env_exe, "-m", "piper"] + sys.argv[1:])

View File

@@ -1,29 +0,0 @@
#!/usr/bin/env bash
# Runs formatters, linters, and type checkers on Python code.
set -eo pipefail
# Directory of *this* script
this_dir="$( cd "$( dirname "$0" )" && pwd )"
base_dir="$(realpath "${this_dir}/..")"
# Path to virtual environment
: "${venv:=${base_dir}/.venv}"
if [ -d "${venv}" ]; then
# Activate virtual environment if available
source "${venv}/bin/activate"
fi
python_files=("${base_dir}/piper")
# Format code
black "${python_files[@]}"
isort "${python_files[@]}"
# Check
flake8 "${python_files[@]}"
pylint "${python_files[@]}"
mypy "${python_files[@]}"

View File

@@ -1,17 +0,0 @@
#!/usr/bin/env bash
set -eo pipefail
# Directory of *this* script
this_dir="$( cd "$( dirname "$0" )" && pwd )"
base_dir="$(realpath "${this_dir}/..")"
# Path to virtual environment
: "${venv:=${base_dir}/.venv}"
if [ -d "${venv}" ]; then
# Activate virtual environment if available
source "${venv}/bin/activate"
fi
python3 -m piper "$@"

View File

@@ -33,6 +33,7 @@ setup(
]
},
install_requires=requirements,
extras_require={"gpu": ["onnxruntime-gpu>=1.11.0,<2"]},
classifiers=[
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",