Skip to content

Commit

Permalink
🗣️ fix: Azure OpenAI STT (#3731)
Browse files Browse the repository at this point in the history
* Fix for Azure OpenAI STT

* chore(STTService): imports order

---------

Co-authored-by: Danny Avila <danacordially@gmail.com>
  • Loading branch information
maxesse and danny-avila authored Aug 30, 2024
1 parent 7536e64 commit 63b80c3
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions api/server/services/Files/Audio/STTService.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { Readable } = require('stream');
const axios = require('axios');
const FormData = require('form-data');
const { Readable } = require('stream');
const { extractEnvVariable, STTProviders } = require('librechat-data-provider');
const getCustomConfig = require('~/server/services/Config/getCustomConfig');
const { genAzureEndpoint } = require('~/utils');
Expand Down Expand Up @@ -136,8 +137,10 @@ class STTService {
}

const formData = new FormData();
const audioBlob = new Blob([audioBuffer], { type: audioFile.mimetype });
formData.append('file', audioBlob, audioFile.originalname);
formData.append('file', audioBuffer, {
filename: audioFile.originalname,
contentType: audioFile.mimetype,
});

const headers = {
'Content-Type': 'multipart/form-data',
Expand All @@ -146,7 +149,7 @@ class STTService {

[headers].forEach(this.removeUndefined);

return [url, formData, headers];
return [url, formData, { ...headers, ...formData.getHeaders() }];
}

/**
Expand All @@ -171,11 +174,6 @@ class STTService {

const [url, data, headers] = strategy.call(this, sttSchema, audioReadStream, audioFile);

if (!Readable.from && data instanceof FormData) {
const audioBlob = new Blob([audioBuffer], { type: audioFile.mimetype });
data.set('file', audioBlob, audioFile.originalname);
}

try {
const response = await axios.post(url, data, { headers });

Expand Down

0 comments on commit 63b80c3

Please sign in to comment.