3

Script that synthesizes EasyApple intros with Azure's text-to-speech APIs

 2 years ago
source link: https://gist.github.com/LucaTNT/e13f7ef98d26327496925b4520789e39
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Script that synthesizes EasyApple intros with Azure's text-to-speech APIs · GitHub

Instantly share code, notes, and snippets.

Script that synthesizes EasyApple intros with Azure's text-to-speech APIs

import requests

def getToken(): req = requests.post("https://westeurope.api.cognitive.microsoft.com/sts/v1.0/issuetoken", 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 = requests.post("https://westeurope.tts.speech.microsoft.com/cognitiveservices/v1", headers=headers, data=f"""<speak version='1.0' xml:lang='it-IT'><voice xml:lang='it-iT' xml:gender='Female' name='it-IT-ElsaNeural'> {text} </voice></speak>""" )

return req.content

def getLastEpisodeNumber(show="easyapple"): req = requests.get(f"https://www.easypodcast.it/api/v1/show/{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 {ultimi_donatori.main()}. " testo += "E ora la parola ai conduttori, Luca Zorzi e Federico Travaini."

f.write(textToMp3(testo))

print("Done.")


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK