mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
🗣️ feat: Edge TTS engine (#3358)
* feat: MS Edge TTS * feat: Edge TTS; fix: STT hook
This commit is contained in:
parent
01a88991ab
commit
b390ba781f
14 changed files with 379 additions and 129 deletions
|
|
@ -2,6 +2,11 @@ import { useRecoilState } from 'recoil';
|
|||
import { useState } from 'react';
|
||||
import store from '~/store';
|
||||
|
||||
interface VoiceOption {
|
||||
value: string;
|
||||
display: string;
|
||||
}
|
||||
|
||||
function useTextToSpeechBrowser() {
|
||||
const [cloudBrowserVoices] = useRecoilState(store.cloudBrowserVoices);
|
||||
const [isSpeaking, setIsSpeaking] = useState(false);
|
||||
|
|
@ -32,7 +37,30 @@ function useTextToSpeechBrowser() {
|
|||
setIsSpeaking(false);
|
||||
};
|
||||
|
||||
return { generateSpeechLocal, cancelSpeechLocal, isSpeaking };
|
||||
const voices = (): Promise<VoiceOption[]> => {
|
||||
return new Promise((resolve) => {
|
||||
const getAndMapVoices = () => {
|
||||
const availableVoices = speechSynthesis
|
||||
.getVoices()
|
||||
.filter((v) => cloudBrowserVoices || v.localService === true);
|
||||
|
||||
const voiceOptions: VoiceOption[] = availableVoices.map((v) => ({
|
||||
value: v.name,
|
||||
display: v.name,
|
||||
}));
|
||||
|
||||
resolve(voiceOptions);
|
||||
};
|
||||
|
||||
if (speechSynthesis.getVoices().length) {
|
||||
getAndMapVoices();
|
||||
} else {
|
||||
speechSynthesis.onvoiceschanged = getAndMapVoices;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return { generateSpeechLocal, cancelSpeechLocal, isSpeaking, voices };
|
||||
}
|
||||
|
||||
export default useTextToSpeechBrowser;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue