Created
April 29, 2022 11:19
-
-
Save csiebler/43f6452b719fe832fd0075de43b606c4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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