Logo

Google

Orate supports Google's speech and transcription services.

Google offers a wide range of speech and transcription services through their Large Language Models (LLMs), including Google Cloud Speech-to-Text and Google Cloud Text-to-Speech.

Setup

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

import { Google } from 'orate/google';

Configuration

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

const google = new Google();

This will use the GOOGLE_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 google = new Google('your_api_key');

Usage

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

Text to Speech

The Google provider provides a tts function that allows you to create a text-to-speech synthesis function using Google Cloud Text-to-Speech. By default, the tts function uses the en-US-Casual-K model.

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

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

const speech = await speak({
  model: new Google().tts('ar-XA-Wavenet-A'),
  prompt: 'Hello, world!',
});

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

const speech = await speak({
  model: new Google().tts('ar-XA-Wavenet-A', {
    advancedVoiceOptions: {
      lowLatencyJourneySynthesis: true,
    },
  }),
  prompt: 'Hello, world!',
});

Speech to Text

The Google provider provides a stt function that allows you to create a speech-to-text transcription function using Google Cloud Speech-to-Text. Google is unique in the fact that you need to specify a recognizer.

import { transcribe } from 'orate';
import { Google } from 'orate/google';
 
const text = await transcribe({
  model: new Google().stt('projects/{project}/locations/{region}/recognizers/{recognizer}'),
  audio: new File(...),
});

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

const text = await transcribe({
  model: new Google().stt('projects/{project}/locations/{region}/recognizers/{recognizer}', {
    config: {
      adaptation: {
        phraseSets: {
          phrases: ['hello', 'world'],
        },
      },
    },
  }),
  audio: new File(...),
});

On this page