mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-29 05:36:13 +01:00
🌊 feat: update Deepgram SDK integration for STT and remove unused TTS provider
This commit is contained in:
parent
25d51eff31
commit
5eabd2493c
2 changed files with 10 additions and 48 deletions
|
|
@ -158,7 +158,15 @@ class STTService {
|
|||
return [url, formData, { ...headers, ...formData.getHeaders() }];
|
||||
}
|
||||
|
||||
async deepgramSDKProvider(sttSchema, audioReadStream, audioFile) {
|
||||
/**
|
||||
* Transcribes audio using the Deepgram SDK.
|
||||
* @async
|
||||
* @param {Object} sttSchema - The STT schema for Deepgram.
|
||||
* @param {Stream} audioReadStream - The audio data to be transcribed.
|
||||
* @returns {Promise<string>} A promise that resolves to the transcribed text.
|
||||
* @throws {Error} If the transcription fails.
|
||||
*/
|
||||
async deepgramSDKProvider(sttSchema, audioReadStream) {
|
||||
const apiKey = extractEnvVariable(sttSchema.apiKey) || '';
|
||||
const deepgram = createClient(apiKey);
|
||||
|
||||
|
|
@ -194,7 +202,7 @@ class STTService {
|
|||
[configOptions].forEach(this.removeUndefined);
|
||||
|
||||
const { result, error } = await deepgram.listen.prerecorded.transcribeFile(
|
||||
Buffer.isBuffer(audioFile) ? audioFile : audioReadStream,
|
||||
audioReadStream,
|
||||
configOptions,
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -248,52 +248,6 @@ class TTSService {
|
|||
return [url, data, headers];
|
||||
}
|
||||
|
||||
deepgramProvider(ttsSchema, input, voice) {
|
||||
const baseUrl = ttsSchema?.url || 'https://api.deepgram.com/v1/speak';
|
||||
const params = {
|
||||
model: ttsSchema.model,
|
||||
voice: voice,
|
||||
language: ttsSchema.language,
|
||||
};
|
||||
|
||||
const queryParams = Object.entries(params)
|
||||
.filter(([, value]) => value)
|
||||
.map(([key, value]) => `${key}=${value}`)
|
||||
.join('&');
|
||||
|
||||
const url = queryParams ? `${baseUrl}?${queryParams}` : baseUrl;
|
||||
|
||||
if (
|
||||
ttsSchema?.voices &&
|
||||
ttsSchema.voices.length > 0 &&
|
||||
!ttsSchema.voices.includes(voice) &&
|
||||
!ttsSchema.voices.includes('ALL')
|
||||
) {
|
||||
throw new Error(`Voice ${voice} is not available.`);
|
||||
}
|
||||
|
||||
const data = {
|
||||
input,
|
||||
model: ttsSchema?.voices && ttsSchema.voices.length > 0 ? voice : undefined,
|
||||
language: ttsSchema?.language,
|
||||
media_settings: {
|
||||
bit_rate: ttsSchema?.media_settings?.bit_rate,
|
||||
sample_rate: ttsSchema?.media_settings?.sample_rate,
|
||||
},
|
||||
};
|
||||
|
||||
const headers = {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${extractEnvVariable(ttsSchema?.apiKey)}`,
|
||||
};
|
||||
|
||||
if (extractEnvVariable(ttsSchema.apiKey) === '') {
|
||||
delete headers.Authorization;
|
||||
}
|
||||
|
||||
return [url, data, headers];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a TTS request to the specified provider.
|
||||
* @async
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue