Azure openai 语音转文本 -Whisper“代码”:“404”,“消息”:“找不到资源”

问题描述 投票:0回答:1

我正在尝试通过 Azure openai 密钥、端点、部署使用耳语来转录音频文件

尽管我通过在有效区域中部署耳语并获得他们的许可来添加正确的凭据(遵循每个步骤) https://learn.microsoft.com/en-us/azure/ai-services/openai/whisper-quickstart?tabs=powershell&pivots=programming-language-powershell

**收到此错误:错误 404:{“error”:{“code”:“404”,“message”:“找不到资源”}} **

尝试使用与在那里工作相同的部署在天蓝色游乐场上进行转录

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

请帮忙提供代码

azure speech-to-text openai-api azure-openai whisper
1个回答
0
投票

收到此错误:错误 404:{“error”:{“code”:“404”,“message”:“找不到资源”}}

当您在请求中传递了错误的参数,例如(api_key, api_base, api_version)时,就会出现上述错误。

在您的请求中,您传递了错误的 API 版本。在Python代码中传递正确的

api_version=2023-09-01-preview
后,在我的环境中执行成功。

代码:

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}")

输出:

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.

enter image description here

参考: Azure OpenAI 服务 REST API 参考 - Azure OpenAI |微软学习

© www.soinside.com 2019 - 2024. All rights reserved.