Skip to content

Instantly share code, notes, and snippets.

@GOROman
Created June 4, 2023 02:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GOROman/89a72de520fea3f69848aa82049b2d20 to your computer and use it in GitHub Desktop.
Save GOROman/89a72de520fea3f69848aa82049b2d20 to your computer and use it in GitHub Desktop.
Koeiro API を Pythonで使う
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