'use client' import useSWR from 'swr' import React from 'react' import { useTranslation } from 'react-i18next' import { usePathname } from 'next/navigation' import { useFeatures } from '../../hooks' import type { OnFeaturesChange } from '../../types' import ParamsConfig from './params-config' import { Speaker } from '@/app/components/base/icons/src/vender/solid/mediaAndDevices' import { languages } from '@/i18n/language' import { fetchAppVoices } from '@/service/apps' import AudioBtn from '@/app/components/base/audio-btn' type TextToSpeechProps = { onChange?: OnFeaturesChange disabled?: boolean } const TextToSpeech = ({ onChange, disabled, }: TextToSpeechProps) => { const { t } = useTranslation() const textToSpeech = useFeatures(s => s.features.text2speech) const pathname = usePathname() const matched = pathname.match(/\/app\/([^/]+)/) const appId = (matched?.length && matched[1]) ? matched[1] : '' const language = textToSpeech?.language const languageInfo = languages.find(i => i.value === textToSpeech?.language) const voiceItems = useSWR({ appId, language }, fetchAppVoices).data const voiceItem = voiceItems?.find(item => item.value === textToSpeech?.voice) return (