-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.py
122 lines (100 loc) · 4.02 KB
/
settings.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# VoivoClip
#
# アプリケーション設定クラス
#
# Copyright (c) 2023-2024 led-mirage
# このソースコードは MITライセンス の下でライセンスされています。
# ライセンスの詳細については、このプロジェクトのLICENSEファイルを参照してください。
import json
import os
import threading
from voicevox import Voicevox
from voicevox_api import VoicevoxAPI
class Settings:
FILE_VER = 3
def __init__(self, setting_file_path):
self._setting_file_path = setting_file_path
self._lock = threading.Lock()
self._init_member()
def _init_member(self):
self._speaker_id = 3
self._speed_scale = 1.2
self._pitch_scale = 0.0
self._voicevox_server = VoicevoxAPI.DEFALUT_SERVER
self._voicevox_install_path = Voicevox.DEFAULT_INSTALL_PATH
self._replacements = []
# 話者ID
def get_speaker_id(self):
with self._lock:
return self._speaker_id
def set_speaker_id(self, speaker_id):
with self._lock:
self._speaker_id = speaker_id
# 読み上げスピード
def get_speed_scale(self):
with self._lock:
return self._speed_scale
def set_speed_scale(self, speed_scale):
with self._lock:
self._speed_scale = speed_scale
# 声の高さ
def get_pitch_scale(self):
with self._lock:
return self._pitch_scale
def set_pitch_scale(self, pitch_scale):
with self._lock:
self._pitch_scale = pitch_scale
# VOICEVOX サーバーのURL
def get_voicevox_server(self):
with self._lock:
return self._voicevox_server
def set_voicevox_server(self, voicevox_server):
with self._lock:
self._voicevox_server = voicevox_server
# VOICEVOX のインストールパス
def get_voicevox_install_path(self):
with self._lock:
return self._voicevox_install_path
def set_voicevox_install_path(self, install_path):
with self._lock:
self._voicevox_install_path = install_path
# 置換設定
def get_replacements(self):
with self._lock:
return self._replacements
def set_replacements(self, replacements):
with self._lock:
self._replacements = replacements
# 設定ファイルを保存する
def save(self):
with self._lock:
self._save_nolock()
def _save_nolock(self):
with open(self._setting_file_path, "w", encoding="utf-8") as file:
setting = {}
setting["file_ver"] = Settings.FILE_VER
setting["speaker_id"] = self._speaker_id
setting["speed_scale"] = self._speed_scale
setting["pitch_scale"] = self._pitch_scale
setting["voicevox_server"] = self._voicevox_server
setting["voicevox_install_path"] = self._voicevox_install_path
setting["replacements"] = self._replacements
json.dump(setting, file, ensure_ascii=False, indent=4)
# 設定ファイルを読み込む
def load(self):
if not os.path.exists(self._setting_file_path):
self._init_member()
self._save_nolock()
return
with self._lock:
with open(self._setting_file_path, "r", encoding="utf-8") as file:
setting = json.load(file)
file_ver = setting.get("file_ver", 1)
self._speaker_id = setting.get("speaker_id", self._speaker_id)
self._speed_scale = setting.get("speed_scale", self._speed_scale)
self._pitch_scale = setting.get("pitch_scale", self._pitch_scale)
self._voicevox_server = setting.get("voicevox_server", self._voicevox_server)
self._voicevox_install_path = setting.get("voicevox_install_path", self._voicevox_install_path)
self._replacements = setting.get("replacements", self._replacements)
if file_ver < Settings.FILE_VER:
self._save_nolock()