in backend/app.py [0:0]
def getGptSpeechToken():
try:
token = get_managed_identity_token()
fetch_token_url = f"https://{SPEECH_REGION}.api.cognitive.microsoft.com/sts/v1.0/issueToken"
headers = {
'Authorization': f'Bearer {token}',
'Content-Type': 'application/x-www-form-urlencoded'
}
response = requests.post(fetch_token_url, headers=headers)
access_token = str(response.text)
return json.dumps({
'token': access_token,
'region': SPEECH_REGION,
'speechRecognitionLanguage': SPEECH_RECOGNITION_LANGUAGE,
'speechSynthesisLanguage': SPEECH_SYNTHESIS_LANGUAGE,
'speechSynthesisVoiceName': SPEECH_SYNTHESIS_VOICE_NAME
})
except Exception as e:
logging.exception("[webbackend] exception in /api/get-speech-token")
return jsonify({"error": str(e)}), 500