Skip to content

Commit 3add6c8

Browse files
authored
voicevox: init at 0.20.0 (#319403)
2 parents 2daf4d1 + 8896d11 commit 3add6c8

File tree

7 files changed

+579
-0
lines changed

7 files changed

+579
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
lib,
3+
stdenv,
4+
fetchzip,
5+
autoPatchelfHook,
6+
}:
7+
8+
let
9+
platformInfoTable = {
10+
"x86_64-linux" = {
11+
id = "linux-x64";
12+
hash = "sha256-/PD5e0bWgnIsIrvyOypoJw30VkgbOFWV1NJpPS2G0WM=";
13+
};
14+
"aarch64-linux" = {
15+
id = "linux-arm64";
16+
hash = "sha256-zfiorXZyIISZPXPwmcdYeHceDmQXkUhsvTkNZScg648=";
17+
};
18+
"x86_64-darwin" = {
19+
id = "osx-x64";
20+
hash = "sha256-cdNdV1fVPkz6B7vtKZiPsLQGqnIiDtYa9KTcwSkjdJg=";
21+
};
22+
"aarch64-darwin" = {
23+
id = "osx-arm64";
24+
hash = "sha256-Z1dq2t/HBQulbPF23ZCihOrcZHMpTXEQ6yXKORZaFPk=";
25+
};
26+
};
27+
28+
platformInfo =
29+
platformInfoTable.${stdenv.hostPlatform.system}
30+
or (throw "Unsupported system: ${stdenv.hostPlatform.system}");
31+
in
32+
stdenv.mkDerivation (finalAttrs: {
33+
pname = "voicevox-core";
34+
version = "0.15.4";
35+
36+
# Note: Only the prebuilt binaries are able to decrypt the encrypted voice models
37+
src = fetchzip {
38+
url = "https://github.com/VOICEVOX/voicevox_core/releases/download/${finalAttrs.version}/voicevox_core-${platformInfo.id}-cpu-${finalAttrs.version}.zip";
39+
inherit (platformInfo) hash;
40+
};
41+
42+
nativeBuildInputs = lib.optionals stdenv.hostPlatform.isLinux [ autoPatchelfHook ];
43+
44+
buildInputs = [ stdenv.cc.cc.lib ];
45+
46+
installPhase = ''
47+
runHook preInstall
48+
49+
install -Dm755 libonnxruntime.* libvoicevox_core.* -t $out/lib
50+
install -Dm644 model/* -t $out/lib/model
51+
install -Dm644 *.h -t $out/include
52+
install -Dm644 README.txt -t $out/share/doc/voicevox-core
53+
54+
runHook postInstall
55+
'';
56+
57+
meta = {
58+
changelog = "https://github.com/VOICEVOX/voicevox_core/releases/tag/${finalAttrs.version}";
59+
description = "Core library for the VOICEVOX speech synthesis software";
60+
homepage = "https://github.com/VOICEVOX/voicevox_core";
61+
license = with lib.licenses; [
62+
mit
63+
({
64+
name = "VOICEVOX Core Library Terms of Use";
65+
url = "https://github.com/VOICEVOX/voicevox_resource/blob/main/core/README.md";
66+
free = false;
67+
redistributable = true;
68+
})
69+
];
70+
maintainers = with lib.maintainers; [ tomasajt ];
71+
platforms = lib.attrNames platformInfoTable;
72+
sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
73+
};
74+
})
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
diff --git a/pyproject.toml b/pyproject.toml
2+
index fa23446..6a7705c 100644
3+
--- a/pyproject.toml
4+
+++ b/pyproject.toml
5+
@@ -40,7 +40,15 @@ use_parentheses = true
6+
datas = "datas" # PyInstaller's argument
7+
8+
[tool.poetry]
9+
-package-mode = false
10+
+name = "voicevox-engine"
11+
+version = "@version@"
12+
+authors = []
13+
+description = ""
14+
+packages = [ { include = "voicevox_engine" } ]
15+
+include = [ "resources/**/*", "run.py", "engine_manifest.json", "presets.yaml"]
16+
+
17+
+[tool.poetry.scripts]
18+
+voicevox-engine = "run:main"
19+
20+
[tool.poetry.dependencies]
21+
python = "~3.11"
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
diff --git a/lib/open_jtalk/src/mecab/src/char_property.h b/lib/open_jtalk/src/mecab/src/char_property.h
2+
index 35f4b05..9c904ba 100644
3+
--- a/lib/open_jtalk/src/mecab/src/char_property.h
4+
+++ b/lib/open_jtalk/src/mecab/src/char_property.h
5+
@@ -37,7 +37,7 @@ class CharProperty {
6+
inline const char *seekToOtherType(const char *begin, const char *end,
7+
CharInfo c, CharInfo *fail,
8+
size_t *mblen, size_t *clen) const {
9+
- register const char *p = begin;
10+
+ const char *p = begin;
11+
*clen = 0;
12+
while (p != end && c.isKindOf(*fail = getCharInfo(p, end, mblen))) {
13+
p += *mblen;
14+
diff --git a/lib/open_jtalk/src/mecab/src/darts.h b/lib/open_jtalk/src/mecab/src/darts.h
15+
index 91b2eae..d6736cf 100644
16+
--- a/lib/open_jtalk/src/mecab/src/darts.h
17+
+++ b/lib/open_jtalk/src/mecab/src/darts.h
18+
@@ -404,10 +404,10 @@ class DoubleArrayImpl {
19+
T result;
20+
set_result(result, -1, 0);
21+
22+
- register array_type_ b = array_[node_pos].base;
23+
- register array_u_type_ p;
24+
+ array_type_ b = array_[node_pos].base;
25+
+ array_u_type_ p;
26+
27+
- for (register size_t i = 0; i < len; ++i) {
28+
+ for (size_t i = 0; i < len; ++i) {
29+
p = b +(node_u_type_)(key[i]) + 1;
30+
if (static_cast<array_u_type_>(b) == array_[p].check)
31+
b = array_[p].base;
32+
@@ -431,12 +431,12 @@ class DoubleArrayImpl {
33+
size_t node_pos = 0) const {
34+
if (!len) len = length_func_()(key);
35+
36+
- register array_type_ b = array_[node_pos].base;
37+
- register size_t num = 0;
38+
- register array_type_ n;
39+
- register array_u_type_ p;
40+
+ array_type_ b = array_[node_pos].base;
41+
+ size_t num = 0;
42+
+ array_type_ n;
43+
+ array_u_type_ p;
44+
45+
- for (register size_t i = 0; i < len; ++i) {
46+
+ for (size_t i = 0; i < len; ++i) {
47+
p = b; // + 0;
48+
n = array_[p].base;
49+
if ((array_u_type_) b == array_[p].check && n < 0) {
50+
@@ -469,8 +469,8 @@ class DoubleArrayImpl {
51+
size_t len = 0) const {
52+
if (!len) len = length_func_()(key);
53+
54+
- register array_type_ b = array_[node_pos].base;
55+
- register array_u_type_ p;
56+
+ array_type_ b = array_[node_pos].base;
57+
+ array_u_type_ p;
58+
59+
for (; key_pos < len; ++key_pos) {
60+
p = b +(node_u_type_)(key[key_pos]) + 1;
61+
diff --git a/lib/open_jtalk/src/mecab/src/dictionary.cpp b/lib/open_jtalk/src/mecab/src/dictionary.cpp
62+
index 5717d4d..3ab6e1f 100644
63+
--- a/lib/open_jtalk/src/mecab/src/dictionary.cpp
64+
+++ b/lib/open_jtalk/src/mecab/src/dictionary.cpp
65+
@@ -66,7 +66,7 @@ int progress_bar_darts(size_t current, size_t total) {
66+
}
67+
68+
template <typename T1, typename T2>
69+
-struct pair_1st_cmp: public std::binary_function<bool, T1, T2> {
70+
+struct pair_1st_cmp {
71+
bool operator()(const std::pair<T1, T2> &x1,
72+
const std::pair<T1, T2> &x2) {
73+
return x1.first < x2.first;
74+
diff --git a/lib/open_jtalk/src/mecab/src/viterbi.cpp b/lib/open_jtalk/src/mecab/src/viterbi.cpp
75+
index 6277fe9..5ccefb7 100644
76+
--- a/lib/open_jtalk/src/mecab/src/viterbi.cpp
77+
+++ b/lib/open_jtalk/src/mecab/src/viterbi.cpp
78+
@@ -318,11 +318,11 @@ template <bool IsAllPath> bool connect(size_t pos, Node *rnode,
79+
const Connector *connector,
80+
Allocator<Node, Path> *allocator) {
81+
for (;rnode; rnode = rnode->bnext) {
82+
- register long best_cost = 2147483647;
83+
+ long best_cost = 2147483647;
84+
Node* best_node = 0;
85+
for (Node *lnode = end_node_list[pos]; lnode; lnode = lnode->enext) {
86+
- register int lcost = connector->cost(lnode, rnode); // local cost
87+
- register long cost = lnode->cost + lcost;
88+
+ int lcost = connector->cost(lnode, rnode); // local cost
89+
+ long cost = lnode->cost + lcost;
90+
91+
if (cost < best_cost) {
92+
best_node = lnode;
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
{
2+
lib,
3+
fetchFromGitHub,
4+
python3Packages,
5+
replaceVars,
6+
voicevox-core,
7+
}:
8+
9+
python3Packages.buildPythonApplication rec {
10+
pname = "voicevox-engine";
11+
version = "0.20.0";
12+
pyproject = true;
13+
14+
src = fetchFromGitHub {
15+
owner = "VOICEVOX";
16+
repo = "voicevox_engine";
17+
rev = "refs/tags/${version}";
18+
hash = "sha256-Gib5R7oleg+XXyu2V65EqrflQ1oiAR7a09a0MFhSITc=";
19+
};
20+
21+
patches = [
22+
# the upstream package only uses poetry for dependency management, not for package definition
23+
# this patch makes the package installable via poetry-core
24+
(replaceVars ./make-installable.patch {
25+
inherit version;
26+
})
27+
];
28+
29+
build-system = with python3Packages; [
30+
poetry-core
31+
];
32+
33+
dependencies =
34+
[
35+
passthru.pyopenjtalk
36+
]
37+
++ (with python3Packages; [
38+
numpy
39+
fastapi
40+
jinja2
41+
python-multipart
42+
uvicorn
43+
soundfile
44+
pyyaml
45+
pyworld
46+
semver
47+
platformdirs
48+
soxr
49+
pydantic
50+
starlette
51+
]);
52+
53+
pythonRemoveDeps = [
54+
# upstream wants fastapi-slim, but we provide fastapi instead
55+
"fastapi-slim"
56+
];
57+
58+
pythonRelaxDeps = true;
59+
60+
preConfigure = ''
61+
# copy demo metadata to temporary directory
62+
mv resources/character_info test_character_info
63+
64+
# populate the `character_info` directory with the actual model metadata instead of the demo metadata
65+
cp -r --no-preserve=all ${passthru.resources}/character_info resources/character_info
66+
67+
# the `character_info` directory copied from `resources` doesn't exactly have the expected format,
68+
# so we transform them to be acceptable by `voicevox-engine`
69+
pushd resources/character_info
70+
for dir in *; do
71+
# remove unused large files
72+
rm $dir/*/*.png_large
73+
74+
# rename directory from "$name_$uuid" to "$uuid"
75+
mv $dir ''${dir#*"_"}
76+
done
77+
popd
78+
'';
79+
80+
makeWrapperArgs = [
81+
''--add-flags "--voicelib_dir=${voicevox-core}/lib"''
82+
];
83+
84+
preCheck = ''
85+
# some tests assume $HOME actually exists
86+
export HOME=$(mktemp -d)
87+
88+
# since the actual metadata files have been installed to `$out` by this point,
89+
# we can move the demo metadata back to its place for the tests to succeed
90+
rm -r resources/character_info
91+
mv test_character_info resources/character_info
92+
'';
93+
94+
disabledTests = [
95+
# this test checks the behaviour of openapi
96+
# one of the functions returns a slightly different output due to openapi version differences
97+
"test_OpenAPIの形が変わっていないことを確認"
98+
];
99+
100+
nativeCheckInputs = with python3Packages; [
101+
pytestCheckHook
102+
syrupy
103+
httpx
104+
];
105+
106+
passthru = {
107+
resources = fetchFromGitHub {
108+
owner = "VOICEVOX";
109+
repo = "voicevox_resource";
110+
rev = "refs/tags/${version}";
111+
hash = "sha256-m888DF9qgGbK30RSwNnAoT9D0tRJk6cD5QY72FRkatM=";
112+
};
113+
114+
pyopenjtalk = python3Packages.callPackage ./pyopenjtalk.nix { };
115+
};
116+
117+
meta = {
118+
changelog = "https://github.com/VOICEVOX/voicevox_engine/releases/tag/${version}";
119+
description = "Engine for the VOICEVOX speech synthesis software";
120+
homepage = "https://github.com/VOICEVOX/voicevox_engine";
121+
license = lib.licenses.lgpl3Only;
122+
mainProgram = "voicevox-engine";
123+
maintainers = with lib.maintainers; [ tomasajt ];
124+
platforms = lib.platforms.linux ++ lib.platforms.darwin;
125+
};
126+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
{
2+
lib,
3+
python,
4+
buildPythonPackage,
5+
fetchFromGitHub,
6+
fetchzip,
7+
setuptools,
8+
cython_0,
9+
cmake,
10+
numpy,
11+
oldest-supported-numpy,
12+
six,
13+
tqdm,
14+
}:
15+
16+
let
17+
dic-dirname = "open_jtalk_dic_utf_8-1.11";
18+
dic-src = fetchzip {
19+
url = "https://github.com/r9y9/open_jtalk/releases/download/v1.11.1/${dic-dirname}.tar.gz";
20+
hash = "sha256-+6cHKujNEzmJbpN9Uan6kZKsPdwxRRzT3ZazDnCNi3s=";
21+
};
22+
in
23+
buildPythonPackage {
24+
pname = "pyopenjtalk";
25+
version = "0-unstable-2023-09-08";
26+
pyproject = true;
27+
28+
src = fetchFromGitHub {
29+
owner = "VOICEVOX";
30+
repo = "pyopenjtalk";
31+
rev = "b35fc89fe42948a28e33aed886ea145a51113f88";
32+
hash = "sha256-DbZkCMdirI6wSRUQSJrkojyjGmViqGeQPO0kSKiw2gE=";
33+
fetchSubmodules = true;
34+
};
35+
36+
patches = [
37+
# this patch fixes the darwin build
38+
# open_jtalk uses mecab, which uses the register keyword and std::binary_function, which are not allowed in c++17
39+
# this patch removes them
40+
./mecab-remove-deprecated.patch
41+
];
42+
43+
postPatch = ''
44+
substituteInPlace pyproject.toml \
45+
--replace-fail 'setuptools<v60.0' 'setuptools'
46+
'';
47+
48+
build-system = [
49+
setuptools
50+
cython_0
51+
cmake
52+
numpy
53+
oldest-supported-numpy
54+
];
55+
56+
dontUseCmakeConfigure = true;
57+
58+
dependencies = [
59+
setuptools # imports pkg_resources at runtime
60+
numpy
61+
six
62+
tqdm
63+
];
64+
65+
postInstall = ''
66+
ln -s ${dic-src} $out/${python.sitePackages}/pyopenjtalk/${dic-dirname}
67+
'';
68+
69+
meta = {
70+
description = "VOICEVOX's fork of the pyopenjtalk text-to-speech library";
71+
homepage = "https://github.com/VOICEVOX/pyopenjtalk";
72+
license = lib.licenses.mit;
73+
maintainers = with lib.maintainers; [ tomasajt ];
74+
};
75+
}

0 commit comments

Comments
 (0)