forked from VOICEVOX/voicevox_core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
78 lines (59 loc) · 2.12 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import dataclasses
import json
import logging
from argparse import ArgumentParser
from pathlib import Path
from typing import Tuple
import voicevox_core
from voicevox_core import AccelerationMode, AudioQuery, VoicevoxCore
SPEAKER_ID = 0
def main() -> None:
logging.basicConfig(
format="[%(levelname)s] %(filename)s: %(message)s", level="DEBUG"
)
logger = logging.getLogger(__name__)
(acceleration_mode, open_jtalk_dict_dir, text, out) = parse_args()
logger.debug("%s", f"{voicevox_core.METAS=}")
logger.debug("%s", f"{voicevox_core.SUPPORTED_DEVICES=}")
logger.info("%s", f"Initializing ({acceleration_mode=}, {open_jtalk_dict_dir=})")
core = VoicevoxCore(
acceleration_mode=acceleration_mode, open_jtalk_dict_dir=open_jtalk_dict_dir
)
logger.debug("%s", f"{core.is_gpu_mode=}")
logger.info("%s", f"Loading model {SPEAKER_ID}")
core.load_model(SPEAKER_ID)
logger.debug("%s", f"{core.is_model_loaded(0)=}")
logger.info("%s", f"Creating an AudioQuery from {text!r}")
audio_query = core.audio_query(text, SPEAKER_ID)
logger.info("%s", f"Synthesizing with {display_as_json(audio_query)}")
wav = core.synthesis(audio_query, SPEAKER_ID)
out.write_bytes(wav)
logger.info("%s", f"Wrote `{out}`")
def parse_args() -> Tuple[AccelerationMode, Path, str, Path]:
argparser = ArgumentParser()
argparser.add_argument(
"--mode",
default="AUTO",
type=AccelerationMode,
help='モード ("AUTO", "CPU", "GPU")',
)
argparser.add_argument(
"open_jtalk_dict_dir",
type=Path,
help="Open JTalkの辞書ディレクトリ",
)
argparser.add_argument(
"text",
help="読み上げさせたい文章",
)
argparser.add_argument(
"out",
type=Path,
help="出力wavファイルのパス",
)
args = argparser.parse_args()
return (args.mode, args.open_jtalk_dict_dir, args.text, args.out)
def display_as_json(audio_query: AudioQuery) -> str:
return json.dumps(dataclasses.asdict(audio_query), ensure_ascii=False)
if __name__ == "__main__":
main()