|
import requests |
|
|
|
|
|
class StatusError(Exception): |
|
pass |
|
|
|
def synthesis(text, speaker = 1): |
|
url = f"https://api.tts.quest/v3/voicevox/synthesis?text={text}&speaker={speaker}" |
|
resp = requests.get(url) |
|
resp.raise_for_status() |
|
data = resp.json() |
|
is_ready = check_audio_status(data["audioStatusUrl"]) |
|
if not is_ready: |
|
raise StatusError("Unexpected status") |
|
|
|
resp = requests.get(data["mp3DownloadUrl"]) |
|
return resp.content |
|
|
|
|
|
|
|
def check_audio_status(url): |
|
is_ready = False |
|
while not is_ready: |
|
resp = requests.get(url) |
|
resp.raise_for_status() |
|
data = resp.json() |
|
is_ready = data["isAudioReady"] |
|
return is_ready |
|
|
|
|
|
|