🗣️ 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:
Marco Beretta 2024-07-30 09:18:52 -04:00 committed by GitHub
parent 4ffdefc2a8
commit 51cd847606
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 737 additions and 714 deletions

View file

@ -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) {