import requests

URL = "https://tts-api.elhuyar.eus/api/"
API_ID = "YOUR_API_ID"
API_KEY = "YOUR_API_KEY"


def synthesize(text, speaker, language, extension="mp3", pace=1.0):
	params = {"api_id": API_ID, "api_key": API_KEY, "text": text, "speaker": speaker,
		"language": language, "extension": extension, "pace": pace}
	r = requests.post(URL + "standard", json=params)
	if r.status_code != 200:
		error = r.json()
		print("There was an error: %d %s (%s)" % (r.status_code, error["message"], error["error"]))
		return None
	return r.content


audio = synthesize("Kaixo mundua!", "female_high", "eu")
if audio:
	with open("audio.mp3", "wb") as f:
		f.write(audio)
	print("Audio saved to audio.mp3")
