i'm trying to transcribe a audio file by using whisper through Azure openai key,endpoints,deployment
eventhough i.m adding right credencials by deploying in valid region for whisper and with their permission granted(Followed each steps) https://learn.microsoft.com/en-us/azure/ai-services/openai/whisper-quickstart?tabs=powershell&pivots=programming-language-powershell
**getting this error: Error 404: {"error":{"code":"404","message": "Resource not found"}} **
tried transcription on azure playground using same deployment its working there
import os
import requests
# Azure OpenAI credentials
os.environ['AZURE_OPENAI_KEY'] = 'KEY'
os.environ['AZURE_OPENAI_ENDPOINT'] = 'ENDPOINT'
# Azure OpenAI metadata variables
openai = {
'api_key': os.environ.get('AZURE_OPENAI_KEY'),
'api_base': os.environ.get('AZURE_OPENAI_ENDPOINT'),
'api_version': '2023-06-01-preview',
'name': 'deployment name'
}
# Header for authentication
headers = {
'api-key': openai['api_key']
}
# audio file
file_path = '/content/drive/MyDrive/speech2text/sampleaudiO.wav'
# URL for the API endpoint
url = f"{openai['api_base']}/openai/deployments/{openai['name']}/audio/transcriptions?api-version={openai['api_version']}"
try:
# Reading the audio file as binary data
with open(file_path, 'rb') as audio_file:
# Send the request to Azure OpenAI for transcription
response = requests.post(url, headers=headers, files={"file": audio_file})
# Check if the request was successful and print the transcription
if response.status_code == 200:
transcription = response.json().get('text', 'Transcription not available')
print("Transcription:", transcription)
else:
print(f"Error {response.status_code}: {response.text}")
except Exception as e:
print(f"An error occurred: {e}")
here
Please help with code
Getting this error: Error 404: {"error":{"code":"404","message": "Resource not found"}}
The above error occurs when you pass the wrong parameters, such as (api_key, api_base, api_version) in your request.
In your request, you have passed the wrong API version. After passing the correct api_version=2023-09-01-preview
in the Python code, it executed successfully in my environment.
Code:
import os
import requests
os.environ['AZURE_OPENAI_KEY'] = 'xxxx'
os.environ['AZURE_OPENAI_ENDPOINT'] = 'https://resource-name.openai.azure.com'
# Azure OpenAI metadata variables
openai = {
'api_key': os.environ.get('AZURE_OPENAI_KEY'),
'api_base': os.environ.get('AZURE_OPENAI_ENDPOINT'),
'api_version': '2023-09-01-preview',
'name': 'whisper-deployment'
}
headers = {
'api-key': openai['api_key']
}
file_path = './harvard.wav'
url = f"{openai['api_base']}/openai/deployments/{openai['name']}/audio/transcriptions?api-version={openai['api_version']}"
try:
# Reading the audio file as binary data
with open(file_path, 'rb') as audio_file:
response = requests.post(url, headers=headers, files={"file": audio_file})
if response.status_code == 200:
transcription = response.json().get('text', 'Transcription not available')
print("Transcription:", transcription)
else:
print(f"Error {response.status_code}: {response.text}")
except Exception as e:
print(f"An error occurred: {e}")
Output:
Transcription: The stale smell of old beer lingers. It takes heat to bring out the odor. A cold dip restores health and zest. A salt pickle tastes fine with ham. Tacos al pastor are my favorite. A zestful food is the hot cross bun.
Reference: Azure OpenAI Service REST API reference - Azure OpenAI | Microsoft Learn.