Transcription result returns Access denied due to invalid subscription key or wrong API endpoint?
Annie
0
Reputation points
I'm trying to run a batch transcription based on the example here.
I have extracted my subscription key via the screenshot attached:
and am trying to run the code via:
import requests
import json
subscription_key = "<KEY VIA SCREENSHOT>"
service_region = "westus"
endpoint = "https://westus.api.cognitive.microsoft.com/speechtotext/v3.1/transcriptions"
headers = {
"Ocp-Apim-Subscription-Key": subscription_key,
"Content-Type": "application/json"
}
body = {
"contentUrls": [
"https://crbn.us/hello.wav",
"https://crbn.us/whatstheweatherlike.wav"
],
"properties": {
"diarizationEnabled": True,
"wordLevelTimestampsEnabled": True,
"displayFormWordLevelTimestampsEnabled": True,
"channels": [
0,
1
],
"punctuationMode": "DictatedAndAutomatic",
"profanityFilterMode": "Masked",
"diarization": {
"speakers": {
"minCount": 1,
"maxCount": 3
}
}
},
"locale": "en-US",
"displayName": "test"
}
response = requests.post(endpoint, headers=headers, data=json.dumps(body))
# Check the response
if response.status_code == 201:
print("Transcription request submitted successfully!")
response_data = response.json()
print("Full response data:")
print(json.dumps(response_data, indent=2))
transcription_id = response_data['self'].split('/')[-1]
print(f"Transcription ID: {transcription_id}")
else:
print(f"Failed to submit transcription request. Status code: {response.status_code}")
try:
print(response.json())
except json.JSONDecodeError:
print(response.text)
This seems to be able to connect to the API and returns a transcription ID, but clicking into the links generated gives:
{"error":{"code":"401","message":"Access denied due to invalid subscription key or wrong API endpoint. Make sure to provide a valid key for an active subscription and use a correct regional API endpoint for your resource."}}
I have tried regenerating the API keys and am using the same sample data as the example - what is wrong with my code?
Sign in to answer