MindPlug
  • 🧠Introduction
  • 🔹How does it work?
  • 🍁JavaScript SDK
  • 🌴API
    • 📗API Setup - Text
    • 📗API Setup - Audio
      • 🔉Performing Transcription
    • 📗API Setup - PDFs
    • 📙Storing Data
    • 📙Store PDF
    • 📙Store Web
    • 📙Query Data
      • 🧠Using Metadata Filters
    • 📙Query By Ids
    • 📙Query by collection
    • 📙Delete By Ids
    • 📙Delete By Upload Id
    • 📙Delete Collection
    • 📙Delete Project
    • 📙List Projects
    • 📙List Collections
    • 📙Search Web
    • Parse Webpage
Powered by GitBook
On this page
  • 1. Setup OpenAI Key
  • 2. Generate Transcription
  1. API
  2. API Setup - Audio

Performing Transcription

1. Setup OpenAI Key

It's base to generate a base instance for OpenAI using the secret key. To do this, create a file named openai.ts and copy the following code within it:

import Bottleneck from 'bottleneck';
import { Configuration, OpenAIApi } from 'openai';

class CustomFormData extends FormData {
  getHeaders() {
      return {}
  }
}

// helps with rate limits
export const limiterOpenai = new Bottleneck({
  maxConcurrent: 1,
  minTime: 50
});

const configuration = new Configuration({
  apiKey: process.env.NEXT_PUBLIC_OPENAI_API_KEY,
  formDataCtor: CustomFormData
});

const openai = new OpenAIApi(configuration);

export default openai;

2. Generate Transcription

Generating the transcription is now is as a one-liner 😄

const response = await openai.createTranscription(file, 'whisper-1', undefined, 'json', 1, 'en');

The file here is the audio file to create the transcription for. There are multiple ways to read the file, on web you can simply have an input and set type to file as:


const onChangeHandler = async (event) => {
    const file: File = event.target.files[0];
    setFile(file);
};

 
<input accept=".mp3,.wav" onChange={onChangeHandler} type="file" />

Last updated 1 year ago

🌴
📗
🔉