feat: 功能优化
This commit is contained in:
@@ -14,6 +14,7 @@ import { MaterialService } from '@/api/material'
|
||||
import { createDigitalHumanTask, getDigitalHumanTask, cancelTask, retryTask } from '@/api/digitalHuman'
|
||||
import { extractVideoCover } from '@/utils/video-cover'
|
||||
import { useUpload } from '@/composables/useUpload'
|
||||
import { DEFAULT_VOICE_PROVIDER } from '@/config/voiceConfig'
|
||||
|
||||
// 导入 voiceStore 用于获取用户音色
|
||||
import { useVoiceCopyStore } from '@/stores/voiceCopy'
|
||||
@@ -249,41 +250,38 @@ const resetPreviewState = () => {
|
||||
}
|
||||
|
||||
const buildPreviewParams = (voice) => {
|
||||
// 公共参数
|
||||
const baseParams = {
|
||||
inputText: ttsText.value,
|
||||
speechRate: speechRate.value || 1.0,
|
||||
audioFormat: 'mp3',
|
||||
timestamp: Date.now(),
|
||||
providerType: DEFAULT_VOICE_PROVIDER
|
||||
}
|
||||
|
||||
if (voice.source === 'user') {
|
||||
// 用户音色:使用voiceConfigId,不传instruction
|
||||
// 用户音色:使用voiceConfigId
|
||||
const configId = voice.rawId || extractIdFromString(voice.id)
|
||||
if (!configId) {
|
||||
message.error('配音配置无效')
|
||||
return null
|
||||
}
|
||||
return {
|
||||
voiceConfigId: configId,
|
||||
inputText: ttsText.value,
|
||||
speechRate: speechRate.value || 1.0,
|
||||
audioFormat: 'mp3',
|
||||
timestamp: Date.now() // 添加时间戳确保每次请求不同
|
||||
}
|
||||
} else {
|
||||
// 系统音色:根据是否选择instruction或emotion来决定传递哪个参数
|
||||
const params = {
|
||||
voiceId: voice.voiceId,
|
||||
inputText: ttsText.value,
|
||||
speechRate: speechRate.value || 1.0,
|
||||
audioFormat: 'mp3',
|
||||
timestamp: Date.now() // 添加时间戳确保每次请求不同
|
||||
}
|
||||
|
||||
// instruction和emotion只能选一个传递
|
||||
if (instruction.value && instruction.value !== 'neutral') {
|
||||
params.instruction = instruction.value
|
||||
} else if (emotion.value && emotion.value !== 'neutral') {
|
||||
params.emotion = emotion.value
|
||||
} else if (voice.defaultInstruction) {
|
||||
params.instruction = voice.defaultInstruction
|
||||
}
|
||||
|
||||
return params
|
||||
return { ...baseParams, voiceConfigId: configId }
|
||||
}
|
||||
|
||||
// 系统音色:使用voiceId,可能包含instruction/emotion
|
||||
const params = { ...baseParams, voiceId: voice.voiceId }
|
||||
|
||||
// instruction和emotion只能选一个传递
|
||||
if (instruction.value && instruction.value !== 'neutral') {
|
||||
params.instruction = instruction.value
|
||||
} else if (emotion.value && emotion.value !== 'neutral') {
|
||||
params.emotion = emotion.value
|
||||
} else if (voice.defaultInstruction) {
|
||||
params.instruction = voice.defaultInstruction
|
||||
}
|
||||
|
||||
return params
|
||||
}
|
||||
|
||||
const extractIdFromString = (idStr) => {
|
||||
@@ -303,7 +301,8 @@ const handleSynthesizeVoice = async () => {
|
||||
const params = {
|
||||
inputText: ttsText.value,
|
||||
speechRate: speechRate.value,
|
||||
audioFormat: 'mp3'
|
||||
audioFormat: 'mp3',
|
||||
providerType: DEFAULT_VOICE_PROVIDER
|
||||
}
|
||||
|
||||
if (voice.source === 'user') {
|
||||
|
||||
@@ -113,8 +113,11 @@ import { MaterialService } from '@/api/material'
|
||||
import { useUpload } from '@/composables/useUpload'
|
||||
import dayjs from 'dayjs'
|
||||
import BasicLayout from '@/layouts/components/BasicLayout.vue'
|
||||
import { VOICE_PROVIDER_OPTIONS, DEFAULT_VOICE_PROVIDER } from '@/config/voiceConfig'
|
||||
|
||||
// ========== 常量 ==========
|
||||
const PROVIDER_OPTIONS = VOICE_PROVIDER_OPTIONS
|
||||
|
||||
const DEFAULT_FORM_DATA = {
|
||||
id: null,
|
||||
name: '',
|
||||
@@ -122,7 +125,8 @@ const DEFAULT_FORM_DATA = {
|
||||
autoTranscribe: true,
|
||||
language: 'zh-CN',
|
||||
gender: 'female',
|
||||
note: ''
|
||||
note: '',
|
||||
providerType: DEFAULT_VOICE_PROVIDER
|
||||
}
|
||||
|
||||
// ========== 响应式数据 ==========
|
||||
@@ -183,7 +187,8 @@ const fillFormData = (data) => {
|
||||
fileId: data.fileId || null,
|
||||
language: data.language || 'zh-CN',
|
||||
gender: data.gender || 'female',
|
||||
note: data.note || ''
|
||||
note: data.note || '',
|
||||
providerType: data.providerType || DEFAULT_VOICE_PROVIDER
|
||||
})
|
||||
}
|
||||
|
||||
@@ -363,7 +368,8 @@ const handleSubmit = async () => {
|
||||
autoTranscribe: formData.autoTranscribe,
|
||||
language: formData.language,
|
||||
gender: formData.gender,
|
||||
note: formData.note
|
||||
note: formData.note,
|
||||
providerType: formData.providerType
|
||||
}
|
||||
: {
|
||||
id: formData.id,
|
||||
|
||||
@@ -13,6 +13,7 @@ import type {
|
||||
} from '../types/identify-face'
|
||||
// @ts-ignore
|
||||
import { VoiceService } from '@/api/voice'
|
||||
import { DEFAULT_VOICE_PROVIDER } from '@/config/voiceConfig'
|
||||
|
||||
/**
|
||||
* 语音生成 Hook
|
||||
@@ -76,6 +77,7 @@ export function useVoiceGeneration(): UseVoiceGeneration {
|
||||
voiceConfigId: voice.rawId || extractIdFromString(voice.id),
|
||||
speechRate: speechRate.value || 1.0,
|
||||
audioFormat: 'mp3' as const,
|
||||
providerType: DEFAULT_VOICE_PROVIDER,
|
||||
}
|
||||
|
||||
const res = await VoiceService.synthesize(params)
|
||||
|
||||
Reference in New Issue
Block a user