Created
June 4, 2023 02:41
-
-
Save GOROman/89a72de520fea3f69848aa82049b2d20 to your computer and use it in GitHub Desktop.
Koeiro API を Pythonで使う
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib.request | |
import json | |
import base64 | |
import pprint | |
# Koeiro パラメータ | |
text = 'スロットルをオフにして' | |
speaker_x = 1.5 | |
speaker_y = 1.5 | |
style = 'talk' # 喜怒哀楽を指定できる | |
seed = 10 | |
# 出力ファイル名 | |
outputFilename = 'voice.wav' | |
params = { | |
'text': text, | |
'speaker_x': speaker_x, | |
'speaker_y': speaker_y, | |
'style': style, | |
'seed': seed | |
} | |
pprint.pprint(params) | |
URL = "https://api.rinna.co.jp/models/cttse/koeiro" | |
req = urllib.request.Request(URL, json.dumps(params).encode(), { | |
'Content-Type': 'application/json'}) | |
with urllib.request.urlopen(req) as res: | |
body = json.load(res) | |
pprint.pprint("Seed:%d\n" % body['seed']) | |
audio = base64.b64decode(body['audio']) | |
with open(outputFilename, 'wb') as f: | |
f.write(audio[15:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment