File size: 2,296 Bytes
4304c6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
'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 (
    <div className='flex items-center px-3 h-12 bg-gray-50 rounded-xl overflow-hidden'>

      <div className='shrink-0 flex items-center justify-center mr-1 w-6 h-6'>

        <Speaker className='w-4 h-4 text-[#7839EE]' />

      </div>

      <div className='shrink-0 mr-2 whitespace-nowrap text-sm text-gray-800 font-semibold'>

        {t('appDebug.feature.textToSpeech.title')}

      </div>

      <div

        className='grow '>

      </div>

      <div className='shrink-0 text-xs text-gray-500 inline-flex items-center gap-2'>

        {languageInfo && (`${languageInfo?.name} - `)}{voiceItem?.name ?? t('appDebug.voice.defaultDisplay')}

        { languageInfo?.example && (

          <AudioBtn

            value={languageInfo?.example}

            noCache={false}

            isAudition={true}

          />

        )}

      </div>

      <div className='shrink-0 flex items-center'>

        <ParamsConfig onChange={onChange} disabled={disabled} />

      </div>

    </div>
  )
}
export default React.memo(TextToSpeech)