Why am I getting this error trying to translate an audio file with WhisperAI?
Here is the code, exactly as in the documentation:
import fs from 'fs';
import OpenAI from 'openai';
const API_KEY = 'XXXXXXXXXXXXXXXXXXXXXXX'; // The key is correct!
const openai = new OpenAI({
apiKey: API_KEY
});
async function translateAudio() {
try {
const translation = await openai.audio.translations.create({
file: fs.createReadStream('d:/Audio/audiofile.mp3'),
model: 'whisper-1',
});
console.log(translation);
} catch (error) {
console.log(error);
}
}
translateAudio()
Here is the error:
PS D:\Projects\NodeApps> node whisper
APIConnectionError: Connection error.
at OpenAI.makeRequest (file:///D:/Projects/NodeApps/node_modules/openai/core.mjs:316:19)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async translateAudio (file:///D:/Projects/NodeApps/whisper.js:12:25) {
status: undefined,
headers: undefined,
request_id: undefined,
error: undefined,
code: undefined,
param: undefined,
type: undefined,
cause: FetchError: request to https://api.openai.com/v1/audio/translations failed, reason: read ECONNRESET
at ClientRequest.<anonymous> (D:\Projects\NodeApps\node_modules\node-fetch\lib\index.js:1501:11)
at ClientRequest.emit (node:events:519:28)
at emitErrorEvent (node:_http_client:101:11)
at TLSSocket.socketErrorListener (node:_http_client:504:5)
at TLSSocket.emit (node:events:531:35)
at emitErrorNT (node:internal/streams/destroy:169:8)
at emitErrorCloseNT (node:internal/streams/destroy:128:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
type: 'system',
errno: 'ECONNRESET',
code: 'ECONNRESET'
}
}