

Check your subscription key and headers.\n") Print("\nStatus code: " + str(response.status_code) + "\nSomething went wrong. Print("\nStatus code: " + str(response.status_code) + "\nYour TTS is ready for playback.\n") With open('sample-' + self.timestr + '.wav', 'wb') as audio: If a success response is returned, then the binary audio is written Response = requests.post(constructed_url, headers=headers, data=body) t('name', 'Microsoft Server Speech Text to Speech Voice (en-US, Guy24KRUS)') Voice = ElementTree.SubElement(xml_body, 'voice') Xml_body = ElementTree.Element('speak', version='1.0') 'X-Microsoft-OutputFormat': 'riff-24khz-16bit-mono-pcm', 'Authorization': 'Bearer ' + self.access_token,

Response = requests.post(fetch_token_url, headers=headers) 'Ocp-Apim-Subscription-Key': self.subscription_key Subscription key for an access token that is valid for ten minutes. The TTS endpoint requires an access token. Self.timestr = time.strftime("%Y%m%d-%H%M") Self.tts = input("What would you like to convert to speech: ")

Print('Environment variable for your subscription key is not set.') Variables to secure your subscription keys. However, we do recommend using environment If you prefer, you can hardcode your subscription key as a string and remove This is the code for text to speech in Python using default voice.Īfter you've set your subscription key, run this application from your workingĭirectory with this command: python TTSSample.py I deployed a voice font and a endpoint for my voice. Hi, I would like to create a system that can change text to speech using my own voice in Python.
