Share via


Quickstart: Spraak naar tekst met het Azure OpenAI Whisper-model

In deze quickstart gebruikt u het Azure OpenAI Whisper-model voor spraak-naar-tekst.

De bestandsgrootte voor het Azure OpenAI Whisper-model is 25 MB. Als u een bestand wilt transcriberen dat groter is dan 25 MB, kunt u de Transcriptie-API van Azure AI Speech gebruiken.

Vereisten

Notitie

Op dit moment moet u een toepassing indienen om toegang te krijgen tot de Azure OpenAI-service. Als u toegang wilt aanvragen, vult u dit formulier in.

Instellingen

Sleutel en eindpunt ophalen

Als u azure OpenAI wilt aanroepen, hebt u een eindpunt en een sleutel nodig.

Naam van de variabele Waarde
AZURE_OPENAI_ENDPOINT Deze waarde vindt u in de sectie Sleutels en eindpunt bij het onderzoeken van uw resource vanuit de Azure Portal. U kunt ook de waarde vinden in de codeweergave van Azure OpenAI Studio>Playground>. Een voorbeeldeindpunt is: https://aoai-docs.openai.azure.com/.
AZURE_OPENAI_API_KEY Deze waarde vindt u in de sectie Sleutels en eindpunt bij het onderzoeken van uw resource vanuit de Azure Portal. U kunt KEY1 of KEY2 gebruiken.

Ga naar uw resource in Azure Portal. Het eindpunt en de sleutels vindt u in de sectie Resourcebeheer . Kopieer uw eindpunt en toegangssleutel, omdat u beide nodig hebt voor het verifiëren van uw API-aanroepen. U kunt KEY1 of KEY2 gebruiken. Als u altijd twee sleutels hebt, kunt u sleutels veilig roteren en opnieuw genereren zonder een serviceonderbreking te veroorzaken.

Schermopname van de overzichtsgebruikersinterface voor een Azure OpenAI-resource in De Azure-portal met de locatie voor eindpunt- en toegangssleutels in rood omcirkeld.

Maak en wijs permanente omgevingsvariabelen toe voor uw sleutel en eindpunt.

Omgevingsvariabelen

setx AZURE_OPENAI_API_KEY "REPLACE_WITH_YOUR_KEY_VALUE_HERE" 
setx AZURE_OPENAI_ENDPOINT "REPLACE_WITH_YOUR_ENDPOINT_HERE" 

REST-API

Voer in een bash-shell de volgende opdracht uit. U moet vervangen door YourDeploymentName de implementatienaam die u hebt gekozen bij het implementeren van het Fluistermodel. De implementatienaam is niet noodzakelijkerwijs hetzelfde als de modelnaam. Als u de modelnaam invoert, treedt er een fout op, tenzij u een implementatienaam hebt gekozen die identiek is aan de naam van het onderliggende model.

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"

De indeling van de eerste regel van de opdracht met een voorbeeldeindpunt wordt als volgt curl https://aoai-docs.openai.azure.com/openai/deployments/{YourDeploymentName}/audio/transcriptions?api-version=2024-02-01 \weergegeven.

U kunt voorbeeldaudiobestanden ophalen uit de Azure AI Speech SDK-opslagplaats op GitHub.

Belangrijk

Gebruik voor productie een veilige manier om uw referenties op te slaan en te openen, zoals Azure Key Vault. Zie het artikel over beveiliging van Azure AI-services voor meer informatie over referentiebeveiliging.

Uitvoer

{"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

Voer de volgende opdracht uit. U moet vervangen door YourDeploymentName de implementatienaam die u hebt gekozen bij het implementeren van het Fluistermodel. De implementatienaam is niet noodzakelijkerwijs hetzelfde als de modelnaam. Als u de modelnaam invoert, treedt er een fout op, tenzij u een implementatienaam hebt gekozen die identiek is aan de naam van het onderliggende model.

# 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

U kunt voorbeeldaudiobestanden ophalen uit de Azure AI Speech SDK-opslagplaats op GitHub.

Belangrijk

Gebruik voor productie een veilige manier om uw referenties op te slaan en te openen, zoals Het PowerShell-geheimbeheer met Azure Key Vault. Zie het artikel over beveiliging van Azure AI-services voor meer informatie over referentiebeveiliging.

Uitvoer

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

Vereisten

Instellingen

Installeer de OpenAI Python-clientbibliotheek met:

pip install openai
  1. Maak een nieuw Python-bestand met de naam quickstart.py. Open deze vervolgens in uw favoriete editor of IDE.

  2. Vervang de inhoud van quickstart.py door de volgende code. Wijzig de code om uw implementatienaam toe te voegen:

    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)

Voer de toepassing uit met de Python-opdracht in uw quickstart-bestand:

U kunt voorbeeldaudiobestanden ophalen uit de Azure AI Speech SDK-opslagplaats op GitHub.

Belangrijk

Gebruik voor productie een veilige manier om uw referenties op te slaan en te openen, zoals Azure Key Vault. Zie het artikel over beveiliging van Azure AI-services voor meer informatie over referentiebeveiliging.

Uitvoer

{"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."}

Resources opschonen

Als u een Azure OpenAI-resource wilt opschonen en verwijderen, kunt u de resource verwijderen. Voordat u de resource verwijdert, moet u eerst geïmplementeerde modellen verwijderen.

Volgende stappen