Generative AI with Node.js in Hindi #11 Generate Text from Audio

OpenAI and Node : Audio to Text


Steps and Points:-


  1. Use OpenAI transcriptions feature
  2. pass file path
  3. Check output
  4. Save text file in Project
  5. Interview Questions
  6. Code and Notes link


Code:-

import OpenAI from "openai";
import dotenv from 'dotenv'
import {createReadStream, writeFileSync} from 'fs'

dotenv.config()

const client = new OpenAI({apiKey:process.env.openAI_Key})
async function main(){
const textResponse= await client.audio.transcriptions.create({
model:"whisper-1",
file:createReadStream('sample-0.mp3'),
language:'en'

})

console.log(textResponse.text);
const rawText=textResponse.text;
writeFileSync("audioToText2.txt",rawText,"utf-8")
}

main();