mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-19 09:50:15 +01:00
🗣️ refactor: speech services; fix: OpenAI STT (#3431)
* fix: OpenAI STT * refactor: STT and TTS service, slightly imporve of performance * fix(DecibelSelector): update default value
This commit is contained in:
parent
4ffdefc2a8
commit
51cd847606
8 changed files with 737 additions and 714 deletions
|
|
@ -45,7 +45,9 @@ const useSpeechToTextExternal = (onTranscriptionComplete: (text: string) => void
|
|||
|
||||
const cleanup = () => {
|
||||
if (mediaRecorderRef.current) {
|
||||
mediaRecorderRef.current.removeEventListener('dataavailable', handleDataAvailable);
|
||||
mediaRecorderRef.current.removeEventListener('dataavailable', (event: BlobEvent) => {
|
||||
audioChunks.push(event.data);
|
||||
});
|
||||
mediaRecorderRef.current.removeEventListener('stop', handleStop);
|
||||
mediaRecorderRef.current = null;
|
||||
}
|
||||
|
|
@ -68,14 +70,6 @@ const useSpeechToTextExternal = (onTranscriptionComplete: (text: string) => void
|
|||
}
|
||||
};
|
||||
|
||||
const handleDataAvailable = (event: BlobEvent) => {
|
||||
if (event.data.size > 0) {
|
||||
audioChunks.push(event.data);
|
||||
} else {
|
||||
showToast({ message: 'No audio data available', status: 'warning' });
|
||||
}
|
||||
};
|
||||
|
||||
const handleStop = () => {
|
||||
if (audioChunks.length > 0) {
|
||||
const audioBlob = new Blob(audioChunks, { type: 'audio/wav' });
|
||||
|
|
@ -139,7 +133,9 @@ const useSpeechToTextExternal = (onTranscriptionComplete: (text: string) => void
|
|||
try {
|
||||
setAudioChunks([]);
|
||||
mediaRecorderRef.current = new MediaRecorder(audioStream.current);
|
||||
mediaRecorderRef.current.addEventListener('dataavailable', handleDataAvailable);
|
||||
mediaRecorderRef.current.addEventListener('dataavailable', (event: BlobEvent) => {
|
||||
audioChunks.push(event.data);
|
||||
});
|
||||
mediaRecorderRef.current.addEventListener('stop', handleStop);
|
||||
mediaRecorderRef.current.start(100);
|
||||
if (!audioContextRef.current && autoTranscribeAudio && speechToText) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue