Generative AI with Node.js in Hindi #11 Generate Text from Audio
OpenAI and Node : Audio to Text
Steps and Points:-
- Use OpenAI transcriptions feature
- pass file path
- Check output
- Save text file in Project
- Interview Questions
- 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();