Skip to content

armgit / piper

Public Imported from GitHub
0

A fast, local neural text to speech system

Slight refactor of scripts, cleaning

Michael Hansen3d1f4463cf24
diff --git a/src/python_run/mypy.ini b/src/python_run/mypy.ini
index 0fae4b9..d38a400 100644
--- a/src/python_run/mypy.ini
+++ b/src/python_run/mypy.ini
@@ -2,3 +2,6 @@
[mypy-onnxruntime.*]
ignore_missing_imports = True
+
+[mypy-piper_phonemize.*]
+ignore_missing_imports = True
diff --git a/src/python_run/piper/voice.py b/src/python_run/piper/voice.py
index 1edda09..9fb2906 100644
--- a/src/python_run/piper/voice.py
+++ b/src/python_run/piper/voice.py
@@ -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,
),
)
diff --git a/src/python_run/pylintrc b/src/python_run/pylintrc
index ea7eeab..b7e98a8 100644
--- a/src/python_run/pylintrc
+++ b/src/python_run/pylintrc
@@ -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,
diff --git a/src/python_run/requirements_dev.txt b/src/python_run/requirements_dev.txt
index 3401b9b..77190e6 100644
--- a/src/python_run/requirements_dev.txt
+++ b/src/python_run/requirements_dev.txt
@@ -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
diff --git a/src/python_run/requirements_gpu.txt b/src/python_run/requirements_gpu.txt
new file mode 100644
index 0000000..9dfdadd
--- /dev/null
+++ b/src/python_run/requirements_gpu.txt
@@ -0,0 +1 @@
+onnxruntime-gpu>=1.11.0,<2
diff --git a/src/python_run/scripts/format b/src/python_run/script/format
similarity index 100%
rename from src/python_run/scripts/format
rename to src/python_run/script/format
diff --git a/src/python_run/scripts/lint b/src/python_run/script/lint
similarity index 100%
rename from src/python_run/scripts/lint
rename to src/python_run/script/lint
diff --git a/src/python_run/script/piper b/src/python_run/script/piper
new file mode 100755
index 0000000..945af5e
--- /dev/null
+++ b/src/python_run/script/piper
@@ -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:])
diff --git a/src/python_run/scripts/setup b/src/python_run/script/setup
similarity index 100%
rename from src/python_run/scripts/setup
rename to src/python_run/script/setup
diff --git a/src/python_run/scripts/check.sh b/src/python_run/scripts/check.sh
deleted file mode 100755
index 85bb211..0000000
--- a/src/python_run/scripts/check.sh
+++ /dev/null
@@ -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[@]}"
diff --git a/src/python_run/scripts/piper b/src/python_run/scripts/piper
deleted file mode 100755
index 3123a0b..0000000
--- a/src/python_run/scripts/piper
+++ /dev/null
@@ -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 "$@"
diff --git a/src/python_run/setup.py b/src/python_run/setup.py
index f53eca2..ad75077 100644
--- a/src/python_run/setup.py
+++ b/src/python_run/setup.py
@@ -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",