-
Notifications
You must be signed in to change notification settings - Fork 0
/
vvox.py
34 lines (31 loc) · 927 Bytes
/
vvox.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
# -*- coding: utf-8 -*-
import json
import requests
import pyaudio
def vvox(text, host='127.0.0.1', port=50021, speaker=3):
params = {
'text': text,
'speaker': speaker,
}
query = requests.post(
f'http://{host}:{port}/audio_query',
params=params,
)
synthesis = requests.post(
f'http://{host}:{port}/synthesis',
headers={'Content-Type': 'application/json'},
params=params,
data=json.dumps(query.json()),
)
voice = synthesis.content
pya = pyaudio.PyAudio()
stream = pya.open(
format=pyaudio.paInt16, # 16bit
channels=1, # モノラル
rate=24000, # 設定の「音声のサンプリングレート」に合わせる デフォルトは24000
output=True,
)
stream.write(voice)
stream.stop_stream()
stream.close()
pya.terminate()