Prompt Chain

Transcribe Audio with Azure OpenAI Whisper

A notebook showing how to transcribe audio to text using the Azure OpenAI Whisper model.

Works with azuregithub

69
Spark score
out of 100
Updated 22 days ago
Version 1.0.0
Models

Add to Favorites

Why it matters

Integrate Azure OpenAI's Whisper model into your applications to automatically transcribe audio files, enabling efficient speech-to-text conversion for various use cases.

Outcomes

What it gets done

01

Configure the OpenAI SDK for Azure

02

Authenticate with Azure OpenAI Service using API keys or Azure AD

03

Transcribe audio files using the `openai.Audio.transcribe` method

04

Extract text from audio streams

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/oai-whisper | bash

Steps

Steps in the chain

01
Install dependencies
02
Import libraries and configure SDK
03
Create Azure resources
04
Get endpoint and configure SDK
05
Authenticate using API key
06
Authenticate using Azure Active Directory
07
Transcribe audio to text

Overview

Azure audio whisper (preview) example

A notebook covering Azure OpenAI Whisper transcription setup - resource creation, endpoint configuration, API key or Active Directory authentication, and calling openai.Audio.transcribe. Use it as a reference for the Azure-specific setup steps for Whisper transcription - it targets a pre-1.0 openai library, so treat it as a walkthrough rather than copy-paste-ready code.

What it does

This notebook shows how to use the Azure OpenAI Whisper model to transcribe audio files. Setup requires creating the proper resources in the Azure Portal, then configuring the OpenAI Python SDK with the resource's endpoint (found under Resource Management > Keys and Endpoints). For development it recommends setting these as environment variables rather than hardcoding them:

OPENAI_API_BASE
OPENAI_API_KEY
OPENAI_API_TYPE
OPENAI_API_VERSION

Authentication supports two mechanisms: an Azure API key (api_type set to azure, with the key found in the same Keys and Endpoints section), or Microsoft Active Directory Authentication, which issues a token that expires and must be refreshed by hooking into requests.auth. Once authenticated, audio transcription - converting spoken words into text - uses the openai.Audio.transcribe method against an audio file stream. The notebook points to the Azure AI Speech SDK's sample audio files on GitHub as a source of test files.

When to use - and when NOT to

Use it as a reference for wiring up Azure-hosted Whisper transcription specifically - resource creation, endpoint configuration, and both authentication paths. The notebook itself flags that a newer version of the openai library is available, so treat this as a walkthrough of the Azure-specific setup (resource, endpoint, auth) rather than copy-paste-ready code for a current SDK version.

Inputs and outputs

Input is an Azure OpenAI resource with a deployed Whisper model, its endpoint and API key or Active Directory token, and an audio file stream. Output is the transcribed text of the audio.

Integrations

It integrates with the Azure OpenAI service via the Azure Portal for resource setup, Microsoft Active Directory for token-based authentication, and can use sample audio files from the Azure AI Speech SDK's GitHub repository for testing.

Who it's for

Developers setting up Azure-hosted Whisper transcription for the first time who need the Azure-specific resource, endpoint, and authentication steps rather than the standard OpenAI API flow.

Source README

Azure audio whisper (preview) example

Note: There is a newer version of the openai library available. See https://github.com/openai/openai-python/discussions/742

The example shows how to use the Azure OpenAI Whisper model to transcribe audio files.

Setup

First, we install the necessary dependencies.

Next, we'll import our libraries and configure the Python OpenAI SDK to work with the Azure OpenAI service.

Note: In this example, we configured the library to use the Azure API by setting the variables in code. For development, consider setting the environment variables instead:

OPENAI_API_BASE
OPENAI_API_KEY
OPENAI_API_TYPE
OPENAI_API_VERSION

To properly access the Azure OpenAI Service, we need to create the proper resources at the Azure Portal (you can check a detailed guide on how to do this in the Microsoft Docs)

Once the resource is created, the first thing we need to use is its endpoint. You can get the endpoint by looking at the "Keys and Endpoints" section under the "Resource Management" section. Having this, we will set up the SDK using this information:

Authentication

The Azure OpenAI service supports multiple authentication mechanisms that include API keys and Azure credentials.

Authentication using API key

To set up the OpenAI SDK to use an Azure API Key, we need to set up the api_type to azure and set api_key to a key associated with your endpoint (you can find this key in "Keys and Endpoints" under "Resource Management" in the Azure Portal)

Authentication using Azure Active Directory

Let's now see how we can get a key via Microsoft Active Directory Authentication.

A token is valid for a period of time, after which it will expire. To ensure a valid token is sent with every request, you can refresh an expiring token by hooking into requests.auth:

Audio transcription

Audio transcription, or speech-to-text, is the process of converting spoken words into text. Use the openai.Audio.transcribe method to transcribe an audio file stream to text.

You can get sample audio files from the Azure AI Speech SDK repository at GitHub.

FAQ

Common questions

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.