How do I use the whisper model from Azure OpenAI API

Ravi K 70 Reputation points
2023-10-09T03:38:28.1866667+00:00

I'm not sure how to use whisper model from Azure OpenAI API. I can use curl and get it to work. I'm looking for python code to access this API.

curl https://WWHISPER_ENDPOINT/openai/deployments/whisper/audio/transcriptions?api-version=2023-09-01-preview -H "api-key: API_KEY -H "Content-Type: multipart/form-data" -F file="@./xXX.mp3"

Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
4,081 questions
0 comments No comments
{count} votes

Accepted answer
  1. Saurabh Sharma 23,846 Reputation points Microsoft Employee Moderator
    2023-10-09T21:07:27.0233333+00:00

    Hi @Ravi K

    Welcome to Microsoft Q&A! Thanks for posting the question.

    You can use the below code in python to use the Whisper model. Please note that you need to install the latest version of openai (0.28.1)

    import openai
    import time
    import os
    
    openai.api_type = "azure"
    openai.api_base = "https://{resourcename}.openai.azure.com/"
    openai.api_key = os.getenv("AOAIKey")
    openai.api_version = "2023-09-01-preview"
    
    model_name = "whisper-1"
    deployment_id = "whisper"
    audio_language="en"
    
    audio_test_file = "./hello.m4a"
    
    result = openai.Audio.transcribe(
                file=open(audio_test_file, "rb"),            
                model=model_name,
                deployment_id=deployment_id
            )
    
    print(result.text)
    

    Please refer to the documentation for additional information.

    Please let me know if you have any questions.

    Thanks

    Saurabh


    Please 'Accept as answer' and Upvote if it helped so that it can help others in the community looking for help on similar topics.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.