-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvox_service.py
67 lines (56 loc) · 1.74 KB
/
vox_service.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
import io
import json
import uuid
import requests
import simpleaudio as sa
import settings
class VoxService:
def __init__(self) -> None:
pass
def speakers(self):
response1 = requests.get(
f"http://{settings.VOX_URL}:{settings.VOX_PORT}/speakers",
)
result = json.loads(s=response1.content)
for speaker in result:
print(speaker["name"])
for styles in speaker["styles"]:
print(f" id: {styles['id']} {styles['name']}")
def voxvoice(self, text: str, voice: int, save: bool = False):
params = (
("text", text),
("speaker", voice),
)
try:
response1 = requests.post(
f"http://{settings.VOX_URL}:{settings.VOX_PORT}/audio_query",
params=params,
)
except:
pass
# vox synth
headers = {"Content-Type": "application/json"}
try:
response2 = requests.post(
f"http://{settings.VOX_URL}:{settings.VOX_PORT}/synthesis",
headers=headers,
params=params,
data=json.dumps(response1.json()),
)
except:
pass
buff = io.BytesIO(response2.content)
buff.seek(0)
# ローカルに保存する場合
if save:
fname = f"fill_voice/{text}.wav"
with open(fname, "wb") as f:
f.write(response2.content)
return fname
return buff
if __name__ == "__main__":
vs = VoxService()
buff = vs.voxvoice("隣の客はよく柿食う客だ", 0)
wave_obj = sa.WaveObject.from_wave_file(buff)
play_obj = wave_obj.play()
play_obj.wait_done()