Logo

OpenAI

Orate supports OpenAI's speech and transcription services.

OpenAI is a leading provider of AI services, offering a wide range of speech and transcription services through their Large Language Models (LLMs). Orate allows you to use these services with a single API, making it easy to switch between providers and use the best AI services for your needs.

Setup

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

import { OpenAI } from 'orate/openai';

Configuration

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

const openai = new OpenAI();

This will use the OPENAI_API_KEY environment variable. If you don't have this variable set, you can pass your API key as an argument to the constructor.

const openai = new OpenAI('your_api_key');

Usage

The OpenAI provider provides a single interface for all of OpenAI's speech and transcription services.

Text to Speech

The OpenAI provider provides a tts function that allows you to create a text-to-speech synthesis function using OpenAI TTS. By default, the tts function uses the tts-1 model and the alloy voice.

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

You can specify the model and voice to use by passing them as arguments to the tts function.

const speech = await speak({
  model: new OpenAI().tts('gpt-4o-mini-tts', 'alloy'),
  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 OpenAI().tts('gpt-4o-mini-tts', 'alloy', {
    speed: 1.25,
  }),
  prompt: 'Hello, world!',
});

You can also stream the speech.

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

Speech to Text

The OpenAI provider provides a stt function that allows you to create a speech-to-text transcription function using OpenAI Whisper. By default, the stt function uses the whisper-1 model.

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

You can specify the model to use by passing it as an argument to the stt function.

const text = await transcribe({
  model: new OpenAI().stt('gpt-4o-mini-transcribe'),
  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 OpenAI().stt('gpt-4o-mini-transcribe', {
    temperature: 0.5,
  }),
  audio: new File(...),
});

You can also stream the transcription.

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

On this page