激活克隆声音

main
guofei 2024-12-03 17:43:19 +08:00
parent ee7a83547e
commit e4dc47a83f
2 changed files with 40 additions and 18 deletions

View File

@ -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: {

View File

@ -161,6 +161,7 @@ export class VolcenAudioSpeakService {
secretKey: VolcenAudioSpeakService.TiktokSecretKeyId,
});
// 激活
try {
const activateVoiceResult = await axios.post(
VolcenAudioSpeakService.ENGIN_BASE_URL_API + '?Action=ActivateMegaTTSTrainStatus&Version=2023-11-07',
activatePost.body,
@ -168,10 +169,18 @@ export class VolcenAudioSpeakService {
headers: activatePost.headers,
},
);
const hasCurrentSpeakId = activateVoiceResult.data?.Result.Statuses.find((item: any) => item.SpeakerID === voiceId);
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;
}
}
/**
* speakId