-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtts.py
More file actions
41 lines (34 loc) · 1.26 KB
/
Copy pathtts.py
File metadata and controls
41 lines (34 loc) · 1.26 KB
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
import argparse
import requests
import sys
TTS_SERVER_HOST = 'tts.mimi.fd.ai'
TTS_SERVER_PATH = '/v1/synthesis/nict'
def synthesize(token, input_lang, text, filename):
headers = {
'Authorization': f'Bearer {token}',
}
data = {
'text': text,
'lang': input_lang,
}
url = f'https://{TTS_SERVER_HOST}{TTS_SERVER_PATH}'
resp = requests.post(url, headers=headers, data=data)
resp.raise_for_status()
with open(filename, 'wb') as fout:
fout.write(resp.content)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('access_token', help='access token file')
parser.add_argument('input_lang', help='input language (e.g. ja)')
parser.add_argument('input_text', help='input text')
parser.add_argument('output_filename', help='output WAV filename')
args = parser.parse_args()
with open(args.access_token, 'r') as f:
token = f.read().strip()
print('start speech synthesis...', file=sys.stderr)
try:
synthesize(token, args.input_lang, args.input_text, args.output_filename)
except Exception as e:
print(f'ERROR: {type(e).__name__}: {e}', file=sys.stderr)
sys.exit(1)
print(f'saved wav file: {args.output_filename}', file=sys.stderr)