Skip to content

Instantly share code, notes, and snippets.

Last active April 20, 2022 15:53
What would you like to do?
Script that synthesizes EasyApple intros with Azure's text-to-speech APIs
import requests
def getToken():
req ="",
headers={"Ocp-Apim-Subscription-Key": "YOUR_AZURE_API_KEY_HERE"},
return req.text
def textToMp3(text, voice="it-IT-ElsaNeural"):
headers = {
"Authorization": f"Bearer: {getToken()}",
"Content-Type": "application/ssml+xml",
"X-Microsoft-OutputFormat": "audio-24khz-160kbitrate-mono-mp3",
"User-Agent": "IntroEasyApple Python 0.1"
req ="",
data=f"""<speak version='1.0' xml:lang='it-IT'><voice xml:lang='it-iT' xml:gender='Female'
return req.content
def getLastEpisodeNumber(show="easyapple"):
req = requests.get(f"{show}/lastEpisode")
response = req.json()
return int(response['episode']['episode_number'])
def getNextEpisodeNumber(show="easyapple"):
return getLastEpisodeNumber(show) + 1
next_episode_number = getNextEpisodeNumber()
donatori = "Luca Z., Federico F." # ultimi_donatori.main() # This is the actual function you don't have access to...
print(f"Prepring intro for episode {next_episode_number}…")
with open(f"/Users/luca/Downloads/intro-{next_episode_number}.mp3", "wb") as f:
testo = f"Benvenuti alla puntata {next_episode_number} di EasyApple. "
if donatori != 'Nessuno, purtroppo':
testo += f"Questa puntata è stata resa possibile dalle donazioni di {donatori}. "
testo += "E ora la parola ai conduttori, Luca Zorzi e Federico Travaini."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment