Im trying to record audio from user and send to whisper to transcribe, but the openai node lib is returning Axios error with 400 bad request.
response: {
status: 400,
statusText: 'Bad Request',
headers: {
date: 'Sat, 15 Apr 2023 16:08:50 GMT',
'content-type': 'application/json',
'content-length': '204',
connection: 'close',
'openai-organization': 'user-',
'openai-processing-ms': '117',
'openai-version': '2020-10-01',
'strict-transport-security': 'max-age=15724800; includeSubDomains',
'x-ratelimit-limit-requests': '50',
'x-ratelimit-remaining-requests': '49',
'x-ratelimit-reset-requests': '1.2s',
'x-request-id': '36c8e2b87112c8e80dc44ee652344c25',
'cf-cache-status': 'DYNAMIC',
server: 'cloudflare',
'cf-ray': '7b85730edf68a5d4-GRU',
'alt-svc': 'h3=":443"; ma=86400, h3-29=":443"; ma=86400'
},
config: {
transitional: [Object],
adapter: [Function: httpAdapter],
transformRequest: [Array],
transformResponse: [Array],
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
maxBodyLength: -1,
validateStatus: [Function: validateStatus],
headers: [Object],
method: 'post',
data: [FormData],
url: 'https://api.openai.com/v1/audio/transcriptions'
},
request: <ref *1> ClientRequest {
_events: [Object: null prototype],
_eventsCount: 7,
_maxListeners: undefined,
outputData: [],
outputSize: 0,
writable: true,
destroyed: false,
_last: true,
chunkedEncoding: true,
shouldKeepAlive: false,
maxRequestsOnConnectionReached: false,
_defaultKeepAlive: true,
useChunkedEncodingByDefault: true,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
strictContentLength: false,
_contentLength: null,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
_closed: false,
socket: [TLSSocket],
_header: 'POST /v1/audio/transcriptions HTTP/1.1\r\n' +
'Accept: application/json, text/plain, */*\r\n' +
'Content-Type: multipart/form-data; boundary=--------------------------5047590565482031\r\n' +
'User-Agent: OpenAI/NodeJS/3.2.1\r\n' +
'Authorization: Bearer sk-\r\n' +
'Host: api.openai.com\r\n' +
'Connection: close\r\n' +
'Transfer-Encoding: chunked\r\n' +
'\r\n',
_keepAliveTimeout: 0,
_onPendingData: [Function: nop],
This is how im requesting:
import FormData from 'form-data';
import { withFileUpload } from 'next-multiparty';
import { createReadStream, read } from 'fs';
const fs = require('fs');
export const config = {
api: {
bodyParser: false,
},
};
const { Configuration, OpenAIApi } = require("openai");
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
export default withFileUpload(async (req, res) => {
const file:any= fs.createReadStream(req.file?.filepath);
const response = await openai.createTranscription(file,"whisper-1").then((res) => console.log(res.data)).catch((err) => console.log(err));
if (response) {
return response.text;
}else{
return "Speech to text failed"
}
});
I tried looking on github, but this error keeps happening.