다음을 통해 공유


빠른 시작: Azure OpenAI Whisper 모델을 사용하여 음성 텍스트 변환

이 빠른 시작에서는 음성 텍스트 변환에 Azure OpenAI Whisper 모델을 사용합니다.

Azure OpenAI Whisper 모델의 파일 크기 제한은 25MB입니다. 25MB보다 큰 파일을 기록해야 하는 경우 Azure AI Speech 일괄 처리 기록 API를 사용할 수 있습니다.

필수 조건

참고 항목

현재 Azure OpenAI Service 에 액세스하려면 신청서를 제출해야 합니다. 액세스를 신청하려면 이 양식을 작성하세요.

설정

키 및 엔드포인트 검색

Azure OpenAI에 대해 성공적으로 호출하려면 엔드포인트가 필요합니다.

변수 이름
AZURE_OPENAI_ENDPOINT 이 값은 Azure Portal에서 리소스를 검사할 때 키 및 엔드포인트 섹션에서 찾을 수 있습니다. 또는 Azure OpenAI Studio>플레이그라운드>코드 보기에서 값을 찾을 수 있습니다. 예제 엔드포인트는 https://aoai-docs.openai.azure.com/입니다.
AZURE_OPENAI_API_KEY 이 값은 Azure Portal에서 리소스를 검사할 때 키 및 엔드포인트 섹션에서 찾을 수 있습니다. KEY1 또는 KEY2를 사용할 수 있습니다.

Azure Portal에서 해당 리소스로 이동합니다. 엔드포인트 및 키리소스 관리 섹션에서 찾을 수 있습니다. 엔드포인트 및 액세스 키를 복사합니다. API 호출을 인증하는 데 모두 필요합니다. KEY1 또는 KEY2를 사용할 수 있습니다. 항상 두 개의 키를 사용하면 서비스 중단 없이 키를 안전하게 회전하고 다시 생성할 수 있습니다.

엔드포인트 & 액세스 키 위치에 빨간색 원이 표시된 Azure Portal의 Azure OpenAI 리소스 개요 UI 스크린샷

키 및 엔드포인트에 대한 영구 환경 변수를 만들고 할당합니다.

환경 변수

setx AZURE_OPENAI_API_KEY "REPLACE_WITH_YOUR_KEY_VALUE_HERE" 
setx AZURE_OPENAI_ENDPOINT "REPLACE_WITH_YOUR_ENDPOINT_HERE" 

REST API

BASH 셸에서 다음 명령을 실행합니다. Whisper 모델을 배포할 때 YourDeploymentName을 선택한 배포 이름으로 바꿔야 합니다. 배포 이름이 모델 이름과 반드시 똑같지는 않습니다. 기본 모델 이름과 동일한 배포 이름을 선택하지 않으면 모델 이름을 입력할 때 오류가 발생합니다.

curl $AZURE_OPENAI_ENDPOINT/openai/deployments/YourDeploymentName/audio/transcriptions?api-version=2024-02-01 \
 -H "api-key: $AZURE_OPENAI_API_KEY" \
 -H "Content-Type: multipart/form-data" \
 -F file="@./wikipediaOcelot.wav"

예시 엔드포인트가 포함된 명령의 첫 번째 줄 형식은 다음과 같습니다. curl https://aoai-docs.openai.azure.com/openai/deployments/{YourDeploymentName}/audio/transcriptions?api-version=2024-02-01 \.

GitHub의 Azure AI Speech SDK 리포지토리에서 샘플 오디오 파일을 가져올 수 있습니다.

Important

프로덕션의 경우 Azure Key Vault와 같은 자격 증명을 안전하게 저장하고 액세스하는 방법을 사용합니다. 자격 증명 보안에 대한 자세한 내용은 Azure AI 서비스 보안 문서를 참조하세요.

출력

{"text":"The ocelot, Lepardus paradalis, is a small wild cat native to the southwestern United States, Mexico, and Central and South America. This medium-sized cat is characterized by solid black spots and streaks on its coat, round ears, and white neck and undersides. It weighs between 8 and 15.5 kilograms, 18 and 34 pounds, and reaches 40 to 50 centimeters 16 to 20 inches at the shoulders. It was first described by Carl Linnaeus in 1758. Two subspecies are recognized, L. p. paradalis and L. p. mitis. Typically active during twilight and at night, the ocelot tends to be solitary and territorial. It is efficient at climbing, leaping, and swimming. It preys on small terrestrial mammals such as armadillo, opossum, and lagomorphs."}

PowerShell

다음 명령을 실행합니다. Whisper 모델을 배포할 때 YourDeploymentName을 선택한 배포 이름으로 바꿔야 합니다. 배포 이름이 모델 이름과 반드시 똑같지는 않습니다. 기본 모델 이름과 동일한 배포 이름을 선택하지 않으면 모델 이름을 입력할 때 오류가 발생합니다.

# Azure OpenAI metadata variables
$openai = @{
    api_key     = $Env:AZURE_OPENAI_API_KEY
    api_base    = $Env:AZURE_OPENAI_ENDPOINT # your endpoint should look like the following https://YOUR_RESOURCE_NAME.openai.azure.com/
    api_version = '2024-02-01' # this may change in the future
    name        = 'YourDeploymentName' #This will correspond to the custom name you chose for your deployment when you deployed a model.
}

# Header for authentication
$headers = [ordered]@{
    'api-key' = $openai.api_key
}

$form = @{ file = get-item -path './wikipediaOcelot.wav' }

# Send a completion call to generate an answer
$url = "$($openai.api_base)/openai/deployments/$($openai.name)/audio/transcriptions?api-version=$($openai.api_version)"

$response = Invoke-RestMethod -Uri $url -Headers $headers -Form $form -Method Post -ContentType 'multipart/form-data'
return $response.text

GitHub의 Azure AI Speech SDK 리포지토리에서 샘플 오디오 파일을 가져올 수 있습니다.

Important

프로덕션의 경우 Azure Key Vault를 사용한 PowerShell 비밀 관리와 같은 자격 증명을 안전하게 저장하고 액세스하는 방법을 사용합니다. 자격 증명 보안에 대한 자세한 내용은 Azure AI 서비스 보안 문서를 참조하세요.

출력

The ocelot, Lepardus paradalis, is a small wild cat native to the southwestern United States, Mexico, and Central and South America. This medium-sized cat is characterized by solid black spots and streaks on its coat, round ears, and white neck and undersides. It weighs between 8 and 15.5 kilograms, 18 and 34 pounds, and reaches 40 to 50 centimeters 16 to 20 inches at the shoulders. It was first described by Carl Linnaeus in 1758. Two subspecies are recognized, L. p. paradalis and L. p. mitis. Typically active during twilight and at night, the ocelot tends to be solitary and territorial. It is efficient at climbing, leaping, and swimming. It preys on small terrestrial mammals such as armadillo, opossum, and lagomorphs.

Python

필수 조건

설정

다음을 사용하여 OpenAI Python 클라이언트 라이브러리를 설치합니다.

pip install openai
  1. quickstart.py라는 새 Python 파일을 만듭니다. 선호하는 편집기 또는 IDE에서 이 파일을 엽니다.

  2. quickstart.py의 내용을 다음 코드로 바꿉니다. 코드를 수정하여 배포 이름을 추가합니다.

    import os
    from openai import AzureOpenAI
        
    client = AzureOpenAI(
        api_key=os.getenv("AZURE_OPENAI_API_KEY"),  
        api_version="2024-02-01",
        azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT")
    )
    
    deployment_id = "YOUR-DEPLOYMENT-NAME-HERE" #This will correspond to the custom name you chose for your deployment when you deployed a model."
    audio_test_file = "./wikipediaOcelot.wav"
    
    result = client.audio.transcriptions.create(
        file=open(audio_test_file, "rb"),            
        model=deployment_id
    )
    
    print(result)

빠른 시작 파일에서 python 명령을 사용하여 애플리케이션을 실행합니다.

GitHub의 Azure AI Speech SDK 리포지토리에서 샘플 오디오 파일을 가져올 수 있습니다.

Important

프로덕션의 경우 Azure Key Vault와 같은 자격 증명을 안전하게 저장하고 액세스하는 방법을 사용합니다. 자격 증명 보안에 대한 자세한 내용은 Azure AI 서비스 보안 문서를 참조하세요.

출력

{"text":"The ocelot, Lepardus paradalis, is a small wild cat native to the southwestern United States, Mexico, and Central and South America. This medium-sized cat is characterized by solid black spots and streaks on its coat, round ears, and white neck and undersides. It weighs between 8 and 15.5 kilograms, 18 and 34 pounds, and reaches 40 to 50 centimeters 16 to 20 inches at the shoulders. It was first described by Carl Linnaeus in 1758. Two subspecies are recognized, L. p. paradalis and L. p. mitis. Typically active during twilight and at night, the ocelot tends to be solitary and territorial. It is efficient at climbing, leaping, and swimming. It preys on small terrestrial mammals such as armadillo, opossum, and lagomorphs."}

리소스 정리

Azure OpenAI 리소스를 정리하고 제거하려면 해당 리소스를 삭제할 수 있습니다. 리소스를 삭제하기 전에 먼저 배포된 모델을 삭제해야 합니다.

다음 단계