Skip to content

Instantly share code, notes, and snippets.

@csiebler
Created April 29, 2022 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csiebler/43f6452b719fe832fd0075de43b606c4 to your computer and use it in GitHub Desktop.
Save csiebler/43f6452b719fe832fd0075de43b606c4 to your computer and use it in GitHub Desktop.
import requests
import azure.cognitiveservices.speech as speechsdk
# This code should run in the backend of the mobile application
headers = {
'Ocp-Apim-Subscription-Key': '<paste your code here>'
}
token_url = 'https://speechapicstest.cognitiveservices.azure.com/sts/v1.0/issuetoken'
response = requests.post(token_url, headers=headers)
access_token = str(response.text)
# Make sure we got back a JWT token
assert(access_token.startswith('ey'))
# This code should run in the frontend mobile application
speech_config = speechsdk.SpeechConfig(auth_token=access_token, region='westeurope')
speech_config.speech_synthesis_language = "en-US"
speech_config.speech_synthesis_voice_name ="en-US-JennyNeural"
audio_config = speechsdk.audio.AudioOutputConfig(use_default_speaker=True)
speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config)
speech_synthesizer.speak_text_async("Hello world, I'm a synthetic voice.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment