From e4dc47a83fec7ca7706a3fa15dc1ab508526e2c1 Mon Sep 17 00:00:00 2001 From: guofei Date: Tue, 3 Dec 2024 17:43:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=BF=80=E6=B4=BB=E5=85=8B=E9=9A=86=E5=A3=B0?= =?UTF-8?q?=E9=9F=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SystemCharter/SystemCharter.controller.ts | 29 ++++++++++++++----- src/services/VolcenAudioSpeakService.ts | 29 ++++++++++++------- 2 files changed, 40 insertions(+), 18 deletions(-) diff --git a/src/modules/SystemCharter/SystemCharter.controller.ts b/src/modules/SystemCharter/SystemCharter.controller.ts index 665533d..f27f641 100644 --- a/src/modules/SystemCharter/SystemCharter.controller.ts +++ b/src/modules/SystemCharter/SystemCharter.controller.ts @@ -164,16 +164,28 @@ export class SystemCharterController { } } - @Get('activateVoice') - async activateVoice(@Query('speakerId') speakerId: string) { + @Post('activateVoice/:roleId') + async activateVoice(@Param('roleId') roleId: string) { try { - if (!speakerId) { - return ApiResponse.failToMessage('参数错误:缺少speakerId'); + if (!roleId) { + return ApiResponse.failToMessage('参数错误:缺少roleId'); + } + const charter = await this.dbService.systemCharter.findUnique({ + where: { id: roleId }, + }); + + if (!charter) { + throw new HttpException('角色不存在', HttpStatus.BAD_REQUEST); } const volcenAudioSpeakService = new VolcenAudioSpeakService(); - const isActivate = await volcenAudioSpeakService.speakActivate(speakerId); + const isActivate = await volcenAudioSpeakService.speakActivate(charter.voiceId); if (isActivate) { + // 修改当前用户的激活状态 + await this.dbService.systemCharter.update({ + where: { id: roleId }, + data: { activate: true }, + }); return ApiResponse.success('音频激活成功'); } else { return ApiResponse.failToMessage('音频激活失败'); @@ -323,13 +335,14 @@ export class SystemCharterController { where: { id: roleId }, }); - // 判断是否有克隆次数 - - if (!charter) { throw new HttpException('角色不存在', HttpStatus.BAD_REQUEST); } + if (!charter.remainingCloneCount || charter.remainingCloneCount <= 0) { + throw new HttpException('剩余克隆次数不足', HttpStatus.BAD_REQUEST); + } + // 检查是否存在未完成的相同角色任务 const existingTask = await this.dbService.taskQueue.findFirst({ where: { diff --git a/src/services/VolcenAudioSpeakService.ts b/src/services/VolcenAudioSpeakService.ts index 706ea3c..1738286 100644 --- a/src/services/VolcenAudioSpeakService.ts +++ b/src/services/VolcenAudioSpeakService.ts @@ -161,16 +161,25 @@ export class VolcenAudioSpeakService { secretKey: VolcenAudioSpeakService.TiktokSecretKeyId, }); // 激活 - const activateVoiceResult = await axios.post( - VolcenAudioSpeakService.ENGIN_BASE_URL_API + '?Action=ActivateMegaTTSTrainStatus&Version=2023-11-07', - activatePost.body, - { - headers: activatePost.headers, - }, - ); - - const hasCurrentSpeakId = activateVoiceResult.data?.Result.Statuses.find((item: any) => item.SpeakerID === voiceId); - return hasCurrentSpeakId; + try { + const activateVoiceResult = await axios.post( + VolcenAudioSpeakService.ENGIN_BASE_URL_API + '?Action=ActivateMegaTTSTrainStatus&Version=2023-11-07', + activatePost.body, + { + headers: activatePost.headers, + }, + ); + const result = activateVoiceResult.data; + console.log('激活结果', result); + if (result?.Result.Statuses) { + const hasCurrentSpeakId = result?.Result.Statuses.find((item: any) => item.SpeakerID === voiceId); + return hasCurrentSpeakId; + } + } catch (error) { + const responseResult = error.response.data; + console.log('激活失败', responseResult); + return null; + } } /**