Add whisper and tts ui (#484)

Co-authored-by: heheer <71265218+newfish-cmyk@users.noreply.github.com>
This commit is contained in:
Archer
2023-11-17 00:03:05 +08:00
committed by GitHub
parent f6aea484ce
commit 4358b6de4d
34 changed files with 806 additions and 333 deletions

View File

@@ -4,9 +4,11 @@ import { getErrText } from '@fastgpt/global/common/error/utils';
import { AppTTSConfigType } from '@/types/app';
import { TTSTypeEnum } from '@/constants/app';
import { useTranslation } from 'next-i18next';
import { useRouter } from 'next/router';
export const useAudioPlay = (props?: { ttsConfig?: AppTTSConfigType }) => {
const { t } = useTranslation();
const { shareId } = useRouter().query as { shareId?: string };
const { ttsConfig } = props || {};
const { toast } = useToast();
const [audio, setAudio] = useState<HTMLAudioElement>();
@@ -16,6 +18,7 @@ export const useAudioPlay = (props?: { ttsConfig?: AppTTSConfigType }) => {
// Check whether the voice is supported
const hasAudio = useMemo(() => {
if (ttsConfig?.type === TTSTypeEnum.none) return false;
if (ttsConfig?.type === TTSTypeEnum.model) return true;
const voices = window.speechSynthesis?.getVoices?.() || []; // 获取语言包
const voice = voices.find((item) => {
return item.lang === 'zh-CN';
@@ -55,7 +58,8 @@ export const useAudioPlay = (props?: { ttsConfig?: AppTTSConfigType }) => {
body: JSON.stringify({
chatItemId,
ttsConfig,
input: text
input: text,
shareId
})
});
setAudioLoading(false);