const fs = require('fs') const OpenAI = require('openai') const { StatusCodes } = require("http-status-codes") const openai = new OpenAI({ apiKey: process.env.TOKEN_OPENAI }) async function speechToTextOpenai(audioPath) { try { const transcription = await openai.audio.transcriptions.create({ file: fs.createReadStream(audioPath), model: "whisper-1", // language: "de", // this is optional but helps the model }) return { msg: `Transcript success`, status: StatusCodes.OK, transcription } } catch (error) { console.log('ERROR ON TRY TRANSCRIPT FROM OPENAI: ', error) return { msg: `Error on try transcript the file`, status: StatusCodes.INTERNAL_SERVER_ERROR } } } module.exports = speechToTextOpenai