python – I have a KeyError: ‘location’ in API Azure Speech

I am using the cognitives services from Azure. I need long audios (more than 10 minutes) and that is why I am following the guide “Long Audio API
” (docs.microsoft.com/en-us/azure/cognitive-services/speech-service/long-audio-api). I have the following code.

def submit_synthesis():
region = ' ********* '
key = '************'
input_file_path="**************************************"
locale = "es-CU"
url="https://{}.customvoice.api.speech.microsoft.com/api/texttospeech/v3.0/longaudiosynthesis".format(region)
header = {
    'Ocp-Apim-Subscription-Key': key
}

voice_identities = [
    {
        'voicename': 'es-CU-ManuelNeural'
    }
]

payload = {
    'displayname': 'long audio synthesis sample',
    'description': 'sample description',
    'locale': locale,
    'voices': json.dumps(voice_identities),
    'outputformat': 'riff-16khz-16bit-mono-pcm',
    'concatenateresult': True,
}

filename = ntpath.basename(input_file_path)
files = {
    'script': (filename, open(input_file_path, 'rb'), 'text/plain')
}

response = requests.post(url, payload, headers=header, files=files)
print('response.status_code: %d' % response.status_code)
print(response.headers['Location'])
submit_synthesis()

The problem is present in print(response.headers['Location'])

    response.status_code: 400
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-22-57595ddb06be> in <module>()
     33     print(response.headers['Location'])
     34 
---> 35 submit_synthesis()

1 frames
/usr/local/lib/python3.7/dist-packages/requests/structures.py in __getitem__(self, key)
     52 
     53     def __getitem__(self, key):
---> 54         return self._store[key.lower()][1]
     55 
     56     def __delitem__(self, key):

KeyError: 'location'

I think probably the problem is “locale”, but I did everything rigth.

Read more here: Source link