Reputation: 1
I am trying to run the Azure speech to text resource on some audio held in blob storage, so I have a python program that creates the file in blob storage and then attempts to run the speech resource on the file, but I keep getting a 415 response and the response content is just "b''", so Im having trouble figuring out what is wrong below is my request code
resp = requests.post(
url,
data={
"displayName": filename,
"locale": "en-GB",
"contentContainerUrl": container_uri,
"ContentUrls": [content_uri],
"properties": {
"diarizationEnabled": False,
"wordLevelTimestampsEnabled": False,
"punctuationMode": "DictatedAndAutomatic",
"profanityFilterMode": "Masked"
}
},
headers={"Ocp-Apim-Subscription-Key": sub_key, "Content-Type": "application/json"}
)
and here is the response
displayName: Recording.wav
Content container url:https://RESOURCE.blob.core.windows.net
contents url: https://RESOURCE.blob.core.windows.net/cnnn-blob/Recording.wav
<Response [415]>
response content: b''
I have searched around for people with similar problems, but theyre accessing different resources, and what worked for them (specifying content type, changing authorization method) isnt working for me. I have also tried uploading the same file converted to different file types, but I dont think the target file is the issue, as the 415 refers to the request itself right?
Upvotes: 0
Views: 58
Reputation: 8140
Make sure you are giving supported audio file like .wav
,
according to this documentation you need to use anyone of the contentContainerUrl
or contentUrls
property.
Use below code.
body = {
"displayName": "sample-1.wav",
"locale": "en-Us",
"contentUrls": ["https://vjgsblob.blob.core.windows.net/data/audio/sample-1.wav?sp=r&st=2025-....sas_token"],
}
resp = requests.post(
"https://eastus.api.cognitive.microsoft.com/speechtotext/v3.2/transcriptions",
data=json.dumps(body),
headers={"Ocp-Apim-Subscription-Key": "key", "Content-Type": "application/json"}
)
Check the transcription job status with below code.
requests.get(resp.json()['self'],
headers={"Ocp-Apim-Subscription-Key": "key", "Content-Type": "application/json"}
).json()
If it is succeeded, then get the details.
details = requests.get(
resp.json()['links']['files'],
headers={"Ocp-Apim-Subscription-Key": "8FphcJAdgP1lQyr3WEUMr8kbRiwlT5N7euy71O7w0NvBbUOLVpq4JQQJ99BAACYeBjFXJ3w3AAAYACOGSAkM", "Content-Type": "application/json"}
)
details.json()
Next make get request to file contentUrl
.
Upvotes: 0