mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
🌩️ feat: cloud-based browser voices (#3297)
* initial voice support * feat: local voices; feat: switch cloud-based voices * feat: apply voice to hook
This commit is contained in:
parent
7d5b03dd98
commit
b34a4ddac1
9 changed files with 177 additions and 37 deletions
|
|
@ -1,12 +1,24 @@
|
|||
import { useRecoilState } from 'recoil';
|
||||
import { useState } from 'react';
|
||||
import store from '~/store';
|
||||
|
||||
function useTextToSpeechBrowser() {
|
||||
const [cloudBrowserVoices] = useRecoilState(store.cloudBrowserVoices);
|
||||
const [isSpeaking, setIsSpeaking] = useState(false);
|
||||
const [voiceName] = useRecoilState(store.voice);
|
||||
|
||||
const generateSpeechLocal = (text: string) => {
|
||||
const synth = window.speechSynthesis;
|
||||
const voices = synth.getVoices().filter((v) => cloudBrowserVoices || v.localService === true);
|
||||
const voice = voices.find((v) => v.name === voiceName);
|
||||
|
||||
if (!voice) {
|
||||
return;
|
||||
}
|
||||
|
||||
synth.cancel();
|
||||
const utterance = new SpeechSynthesisUtterance(text);
|
||||
utterance.voice = voice;
|
||||
utterance.onend = () => {
|
||||
setIsSpeaking(false);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue