mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-12 11:49:07 +08:00
Fix voice selection (#2664)
Co-authored-by: luowei <glpat-EjySCyNjWiLqAED-YmwM> Co-authored-by: crazywoola <427733928@qq.com> Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com>
This commit is contained in:
parent
3c1825187a
commit
6a6133c102
@ -88,7 +88,7 @@ class ChatMessageTextApi(Resource):
|
|||||||
response = AudioService.transcript_tts(
|
response = AudioService.transcript_tts(
|
||||||
tenant_id=app_model.tenant_id,
|
tenant_id=app_model.tenant_id,
|
||||||
text=request.form['text'],
|
text=request.form['text'],
|
||||||
voice=app_model.app_model_config.text_to_speech_dict.get('voice'),
|
voice=request.form['voice'] if request.form['voice'] else app_model.app_model_config.text_to_speech_dict.get('voice'),
|
||||||
streaming=False
|
streaming=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ class ChatTextApi(InstalledAppResource):
|
|||||||
response = AudioService.transcript_tts(
|
response = AudioService.transcript_tts(
|
||||||
tenant_id=app_model.tenant_id,
|
tenant_id=app_model.tenant_id,
|
||||||
text=request.form['text'],
|
text=request.form['text'],
|
||||||
voice=app_model.app_model_config.text_to_speech_dict.get('voice'),
|
voice=request.form['voice'] if request.form['voice'] else app_model.app_model_config.text_to_speech_dict.get('voice'),
|
||||||
streaming=False
|
streaming=False
|
||||||
)
|
)
|
||||||
return {'data': response.data.decode('latin1')}
|
return {'data': response.data.decode('latin1')}
|
||||||
|
@ -87,7 +87,7 @@ class TextApi(Resource):
|
|||||||
tenant_id=app_model.tenant_id,
|
tenant_id=app_model.tenant_id,
|
||||||
text=args['text'],
|
text=args['text'],
|
||||||
end_user=end_user,
|
end_user=end_user,
|
||||||
voice=app_model.app_model_config.text_to_speech_dict.get('voice'),
|
voice=args['voice'] if args['voice'] else app_model.app_model_config.text_to_speech_dict.get('voice'),
|
||||||
streaming=args['streaming']
|
streaming=args['streaming']
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ class TextApi(WebApiResource):
|
|||||||
tenant_id=app_model.tenant_id,
|
tenant_id=app_model.tenant_id,
|
||||||
text=request.form['text'],
|
text=request.form['text'],
|
||||||
end_user=end_user.external_user_id,
|
end_user=end_user.external_user_id,
|
||||||
voice=app_model.app_model_config.text_to_speech_dict.get('voice'),
|
voice=request.form['voice'] if request.form['voice'] else app_model.app_model_config.text_to_speech_dict.get('voice'),
|
||||||
streaming=False
|
streaming=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ class OpenAIText2SpeechModel(_CommonOpenAI, TTSModel):
|
|||||||
:return: text translated to audio file
|
:return: text translated to audio file
|
||||||
"""
|
"""
|
||||||
audio_type = self._get_model_audio_type(model, credentials)
|
audio_type = self._get_model_audio_type(model, credentials)
|
||||||
if not voice:
|
if not voice or voice not in [d['value'] for d in self.get_tts_model_voices(model=model, credentials=credentials)]:
|
||||||
voice = self._get_model_default_voice(model, credentials)
|
voice = self._get_model_default_voice(model, credentials)
|
||||||
if streaming:
|
if streaming:
|
||||||
return Response(stream_with_context(self._tts_invoke_streaming(model=model,
|
return Response(stream_with_context(self._tts_invoke_streaming(model=model,
|
||||||
|
@ -34,7 +34,7 @@ class TongyiText2SpeechModel(_CommonTongyi, TTSModel):
|
|||||||
:return: text translated to audio file
|
:return: text translated to audio file
|
||||||
"""
|
"""
|
||||||
audio_type = self._get_model_audio_type(model, credentials)
|
audio_type = self._get_model_audio_type(model, credentials)
|
||||||
if not voice or voice not in self.get_tts_model_voices(model=model, credentials=credentials):
|
if not voice or voice not in [d['value'] for d in self.get_tts_model_voices(model=model, credentials=credentials)]:
|
||||||
voice = self._get_model_default_voice(model, credentials)
|
voice = self._get_model_default_voice(model, credentials)
|
||||||
if streaming:
|
if streaming:
|
||||||
return Response(stream_with_context(self._tts_invoke_streaming(model=model,
|
return Response(stream_with_context(self._tts_invoke_streaming(model=model,
|
||||||
|
@ -40,6 +40,7 @@ const TextToSpeech: FC = () => {
|
|||||||
{ languageInfo?.example && (
|
{ languageInfo?.example && (
|
||||||
<AudioBtn
|
<AudioBtn
|
||||||
value={languageInfo?.example}
|
value={languageInfo?.example}
|
||||||
|
voice={voiceItem?.value}
|
||||||
isAudition={true}
|
isAudition={true}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
@ -9,12 +9,14 @@ import { textToAudio } from '@/service/share'
|
|||||||
|
|
||||||
type AudioBtnProps = {
|
type AudioBtnProps = {
|
||||||
value: string
|
value: string
|
||||||
|
voice?: string
|
||||||
className?: string
|
className?: string
|
||||||
isAudition?: boolean
|
isAudition?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const AudioBtn = ({
|
const AudioBtn = ({
|
||||||
value,
|
value,
|
||||||
|
voice,
|
||||||
className,
|
className,
|
||||||
isAudition,
|
isAudition,
|
||||||
}: AudioBtnProps) => {
|
}: AudioBtnProps) => {
|
||||||
@ -27,13 +29,16 @@ const AudioBtn = ({
|
|||||||
const pathname = usePathname()
|
const pathname = usePathname()
|
||||||
const removeCodeBlocks = (inputText: any) => {
|
const removeCodeBlocks = (inputText: any) => {
|
||||||
const codeBlockRegex = /```[\s\S]*?```/g
|
const codeBlockRegex = /```[\s\S]*?```/g
|
||||||
|
if (inputText)
|
||||||
return inputText.replace(codeBlockRegex, '')
|
return inputText.replace(codeBlockRegex, '')
|
||||||
|
return ''
|
||||||
}
|
}
|
||||||
|
|
||||||
const playAudio = async () => {
|
const playAudio = async () => {
|
||||||
const formData = new FormData()
|
const formData = new FormData()
|
||||||
if (value !== '') {
|
if (value !== '') {
|
||||||
formData.append('text', removeCodeBlocks(value))
|
formData.append('text', removeCodeBlocks(value))
|
||||||
|
formData.append('voice', removeCodeBlocks(voice))
|
||||||
|
|
||||||
let url = ''
|
let url = ''
|
||||||
let isPublic = false
|
let isPublic = false
|
||||||
|
@ -77,6 +77,7 @@ const Operation: FC<OperationProps> = ({
|
|||||||
{(!isOpeningStatement && config?.text_to_speech?.enabled) && (
|
{(!isOpeningStatement && config?.text_to_speech?.enabled) && (
|
||||||
<AudioBtn
|
<AudioBtn
|
||||||
value={content}
|
value={content}
|
||||||
|
voice={config?.text_to_speech?.voice}
|
||||||
className='hidden group-hover:block'
|
className='hidden group-hover:block'
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user