fix:问题

This commit is contained in:
2026-02-02 02:39:40 +08:00
parent 49c660a6e3
commit 33b748915d
9 changed files with 96 additions and 43 deletions

View File

@@ -22,6 +22,7 @@ export const VoiceService = {
* @param {string} data.language - 语言(可选)
* @param {string} data.gender - 音色类型(可选)
* @param {string} data.note - 备注(可选)
* @param {string} data.text - 音频文本(用于语音复刻,前端通过音频识别获取)
* @param {string} data.providerType - 供应商类型可选cosyvoice-阿里云siliconflow-硅基流动
* @returns {Promise}
*/

View File

@@ -133,28 +133,23 @@ export function useUpload() {
fileType: file.type,
groupId,
coverBase64,
duration: file.type.startsWith('video/') ? null : undefined // 视频时长由后端处理或前端可选传递
duration: file.type.startsWith('video/') ? null : undefined
})
// 设置成功状态
state.uploading = false
state.status = 'success'
state.progress = 100
// 通知成功
const fileId = completeData.data?.infraFileId || completeData.data?.userFileId
onSuccess && onSuccess(fileId)
const fileUrl = presignedData.data.presignedUrl
onSuccess && onSuccess(fileId, fileUrl)
return fileId
} catch (error) {
// 设置错误状态
state.uploading = false
state.status = 'error'
state.error = error.message || '上传失败'
// 通知错误
onError && onError(error)
throw error
}
}

View File

@@ -111,6 +111,7 @@ import { PlusOutlined, SearchOutlined, UploadOutlined, PlayCircleOutlined } from
import { VoiceService } from '@/api/voice'
import { MaterialService } from '@/api/material'
import { useUpload } from '@/composables/useUpload'
import useVoiceText from '@gold/hooks/web/useVoiceText'
import dayjs from 'dayjs'
import BasicLayout from '@/layouts/components/BasicLayout.vue'
@@ -123,7 +124,9 @@ const DEFAULT_FORM_DATA = {
autoTranscribe: true,
language: 'zh-CN',
gender: 'female',
note: ''
note: '',
text: '', // 音频文本
fileUrl: '' // 文件URL用于获取音频文本
}
// ========== 响应式数据 ==========
@@ -155,6 +158,9 @@ const formData = reactive({ ...DEFAULT_FORM_DATA })
// ========== Upload Hook ==========
const { state: uploadState, upload } = useUpload()
// ========== VoiceText Hook ==========
const { getVoiceText } = useVoiceText()
// ========== 计算属性 ==========
const isCreateMode = computed(() => formMode.value === 'create')
@@ -307,13 +313,16 @@ const handleCustomUpload = async (options) => {
try {
const fileId = await upload(file, {
fileCategory: 'voice',
groupId: null, // 配音模块不使用groupId
groupId: null,
coverBase64: null,
onStart: () => {},
onProgress: () => {},
onSuccess: (id) => {
onSuccess: async (id, fileUrl) => {
formData.fileId = id
formData.fileUrl = fileUrl // 保存文件URL
message.success('文件上传成功')
// 通过fileId获取播放URL用于语音识别
await fetchAudioTextById(id)
onSuccess?.({ code: 0, data: id }, file)
},
onError: (error) => {
@@ -330,12 +339,51 @@ const handleCustomUpload = async (options) => {
}
}
// 通过fileId获取音频文本
const fetchAudioTextById = async (fileId) => {
if (!fileId) return
try {
// 获取音频播放URL
const res = await MaterialService.getAudioPlayUrl(fileId)
if (res.code === 0 && res.data) {
const rawFileUrl = res.data
const results = await getVoiceText([{ audio_url: rawFileUrl }])
if (results && results.length > 0) {
const text = results[0].value
formData.text = text
if (text) {
message.success('音频文本获取成功')
}
}
}
} catch (error) {
console.error('获取音频文本失败:', error)
}
}
// 获取音频文本
const fetchAudioText = async (fileUrl) => {
if (!fileUrl) return
try {
// 阿里云语音识别服务无法访问预签名URL使用原始URL
const rawFileUrl = extractRawUrl(fileUrl)
const results = await getVoiceText([{ audio_url: rawFileUrl }])
if (results && results.length > 0) {
const text = results[0].value
formData.text = text
if (text) {
message.success('音频文本获取成功')
}
}
} catch (error) {
console.error('获取音频文本失败:', error)
}
}
const handleFileListChange = (info) => {
// 处理文件列表变化,避免直接修改导致 DOM 错误
const { fileList: newFileList } = info
// 只更新文件列表,不直接修改文件项的状态
// 让组件自己管理状态
if (newFileList) {
fileList.value = newFileList.filter(item => item.status !== 'removed')
}
@@ -363,7 +411,8 @@ const handleSubmit = async () => {
autoTranscribe: formData.autoTranscribe,
language: formData.language,
gender: formData.gender,
note: formData.note
note: formData.note,
text: formData.text // 传入音频文本
}
: {
id: formData.id,