Logo

Azure OpenAI

Orate supports Azure's OpenAI services.

Azure OpenAI is a cloud-based AI platform that provides a range of OpenAI models on their cloud computing platform.

Setup

The Azure OpenAI provider is available by default in Orate. To import it, you can use the following code:

import { AzureOpenAI } from 'orate/azure.openai';

Configuration

You can use Azure OpenAI by creating a new instance of the AzureOpenAI class:

const azureOpenAI = new AzureOpenAI();

This will use the AZURE_OPENAI_API_KEY, AZURE_OPENAI_TTS_ENDPOINT, AZURE_OPENAI_STT_ENDPOINT and AZURE_OPENAI_API_VERSION environment variables. If you don't have these variables set, you can pass your keys as an argument to the constructor.

const azureOpenAI = new AzureOpenAI({
  apiKey: 'your_api_key',
  ttsEndpoint: 'your_tts_endpoint',
  sttEndpoint: 'your_stt_endpoint',
  apiVersion: 'your_api_version',
});

Usage

The Azure OpenAI provider provides a single interface for all of Azure's OpenAI services.

Text to Speech

The Azure OpenAI provider provides a tts function that allows you to create a text-to-speech synthesis function using Azure OpenAI TTS.

import { speak } from 'orate';
import { AzureOpenAI } from 'orate/azure.openai';
 
const speech = await speak({
  model: new AzureOpenAI().tts('tts', 'alloy'),
  prompt: 'Hello, world!',
});

You can specify the voice to use by passing it as an argument to the tts function.

const speech = await speak({
  model: new AzureOpenAI().tts('tts', 'nova'),
  prompt: 'Hello, world!',
});

You can also specify specific OpenAI properties by passing them as an argument to the tts function.

const speech = await speak({
  model: new AzureOpenAI().tts('tts', 'alloy', {
    speed: 1.25,
  }),
  prompt: 'Hello, world!',
});

Speech to Text

The Azure OpenAI provider provides a stt function that allows you to create a speech-to-text transcription function using Azure OpenAI Whisper.

import { transcribe } from 'orate';
import { AzureOpenAI } from 'orate/azure.openai';
 
const text = await transcribe({
  model: new AzureOpenAI().stt('whisper'),
  audio: new File(...),
});

You can also specify specific OpenAI properties by passing them as an argument to the stt function.

const text = await transcribe({
  model: new AzureOpenAI().stt('whisper', {
    temperature: 0.5,
  }),
  audio: new File(...),
});

You can also stream the transcription.

const text = await transcribe({
  model: new AzureOpenAI().stt('whisper'),
  audio: new File(...),
  stream: true,
});

On this page