Commit f21881b9 by haojie

异步洗稿

parent 5e4e82bd
import { liveContentRegenerate, liveContentRegenerateCallback } from '@/utils/api/userApi';
import { writeLog } from '@/utils/pyqt';
import { onBeforeUnmount, ref } from 'vue';
export default function () {
......@@ -34,6 +35,10 @@ export default function () {
openConfuseInterval('');
}
} catch (e) {
writeLog({
name: 'old 洗稿提交',
value: e,
});
console.log(e);
}
};
......@@ -53,6 +58,10 @@ export default function () {
console.log(res.data);
}
} catch (e) {
writeLog({
name: 'old 洗稿回调',
value: e,
});
console.log(e);
}
};
......
import { computed, onBeforeUnmount, ref, watch } from 'vue';
import { useStore } from 'vuex';
import { createLiveKeys, scriptTypeText } from '@/service/CreateLive';
import { createLiveKeys, createLiveVersion, filterFiled } from '@/service/CreateLive';
import { getLiveTtsCallback, createLiveTask, liveTts, liveTaskRegenerate } from '@/utils/api/userApi';
import { DataType, alyOssUpload, dimensionalConvert, isDev, show_message } from '@/utils/tool';
import { audioMerge, splitAudio } from '@/utils/audio';
import { ecursionDeepCopy, isDev, show_message } from '@/utils/tool';
import { useLiveInfoSubmit } from '@/hooks/useStoreCommit';
import { getUploadConfig, onUpdateLiveTask } from '@/service/Common';
import { onUpdateLiveTask, audioStart, uploadToAly } from '@/service/Common';
import { v4 } from 'uuid';
import { useRoute, useRouter } from 'vue-router';
import routerConfig from '@/router/tool';
import useConfuse from '@/hooks/useConfuse';
import CustomException from '@/utils/error';
import { callPyjsInWindow } from '@/utils/pyqt';
import { callPyjsInWindow, writeLog } from '@/utils/pyqt';
// 轮询处理文本脚本语音生成回调
export const processTextCallback = () => {
......@@ -34,9 +33,7 @@ export const processTextCallback = () => {
// 文字转音频轮询
const interval = ref(null);
const createLiveInfo = computed(() => store.getters['live/getLiveInfo']);
const liveName = computed(() => store.getters['live/getName']);
const userInfo = computed(() => store.getters['user/userInfo']);
const alyList = ref([]);
const submitAudioTask = async (list: any[]) => {
let item = createLiveInfo.value;
......@@ -69,127 +66,9 @@ export const processTextCallback = () => {
},
);
// 提交时过滤必要的字段
const filterFiled = (type: string = '') => {
let item = createLiveInfo.value;
// 过滤必须字段
let params: any = {};
params.name = liveName.value;
// 数字人id
params.digital_man_id = item[createLiveKeys.id];
// 是否洗稿
params.is_disorganize = item[createLiveKeys.isDisorganize];
// 脚本类型
params.type = item[createLiveKeys.scriptType];
// 脚本内容
if (item[createLiveKeys.scriptType] == scriptTypeText) {
// 文本
params.type_content = item[createLiveKeys.textScriptValue];
// 转换格式
// 先二维转一维
params.type_content = dimensionalConvert(params.type_content);
let list = [];
params.type_content.forEach((item: any) => {
list.push([item]);
});
params.type_content = list;
console.log(params.type_content, '文本 type_content');
// 音色id
params.phonetic_timbres_id = item[createLiveKeys.textSoundColor];
// 文本内容--先转一维数组
let newList = dimensionalConvert(item[createLiveKeys.textScriptList]);
params.content = newList.map((row: any) => {
return {
title: row.title,
content: row.content,
};
});
} else {
// 切割后的音频格式
const audioConversion = (list: any[]) => {
return list
.map((child: any) => {
return child.audio_url;
})
.join('|');
};
// 音频
params.type_content = item[createLiveKeys.audioScriptList].map((audioScript: any) => {
let list = [];
audioScript.data.forEach((it: any) => {
let params: any = {
content: '',
old_content: '',
name: '',
uuid: v4(),
duration: 0,
};
if (it.duration) {
params.duration = parseInt(it.duration);
}
// 草稿类型的
if (type == 'edit_drafts') {
if (it.children && it.children.length > 1) {
// 有切割的
params.content = audioConversion(it.children);
}
if (it.old_content) {
params.old_content = it.old_content;
} else if (it.url) {
params.old_content = it.url;
}
if (it.content) {
params.content = it.content;
} else if (it.url) {
params.content = it.url;
}
} else {
// 获取编辑状态下的content
if (it.children && it.children.length > 1) {
// 修改content
params.content = audioConversion(it.children);
params.old_content = it.audio_url;
} else {
if (typeof it === 'string') {
params.content = it;
params.old_content = it;
} else if (it.url) {
params.content = it.url;
params.old_content = it.url;
} else {
params.content = it.audio_url;
params.old_content = it.audio_url;
}
}
}
// 切割后的
if (typeof it !== 'string' && it.new_content) {
params.content = it.new_content;
}
// 获取文件名
if (!DataType(it, 'string') && DataType(it, 'object')) {
if (it.name) {
params.name = it.name;
} else if (it.file && it.file.name) {
params.name = it.file.name;
}
}
list.push(params);
});
return list;
});
console.log(params.type_content, '音频 type_content');
// 音色id
params.phonetic_timbres_id = item[createLiveKeys.phoneticsSoundColor];
}
// 音调id
params.tone_id = item[createLiveKeys.textTones];
// 互动库
params.interaction_ids = item[createLiveKeys.interactiveLibrary];
return params;
// 获取createLiveInfo
const getCreateLiveInfo = () => {
return createLiveInfo.value;
};
// 提交后的初始化操作
......@@ -214,15 +93,19 @@ export const processTextCallback = () => {
const submit = async (type: string = 'create') => {
if (type === 'create') {
try {
let res: any = await createLiveTask(filterFiled());
let res: any = await createLiveTask(filterFiled(getCreateLiveInfo()));
if (res.code == 0) {
console.log('提交的参数', JSON.stringify(filterFiled()));
console.log('提交的参数', JSON.stringify(filterFiled(getCreateLiveInfo())));
console.log('创建成功-', res.data.id);
live_task_id.value = res.data.id;
return true;
}
return false;
} catch (e) {
writeLog({
name: '创建直播失败',
value: e,
});
console.log(e);
return false;
}
......@@ -230,7 +113,7 @@ export const processTextCallback = () => {
// 更新
console.log('更新');
try {
let params = filterFiled();
let params = filterFiled(getCreateLiveInfo());
loading.value = true;
let res: any = await onUpdateLiveTask(route.query.id, params);
if (res) {
......@@ -245,6 +128,10 @@ export const processTextCallback = () => {
}
loading.value = false;
} catch (e) {
writeLog({
name: '更新直播失败',
value: e,
});
loading.value = false;
console.log(e);
}
......@@ -267,11 +154,6 @@ export const processTextCallback = () => {
currentSetp.value = 1;
};
// 获取文件名
const getFileName = (file: any) => {
return file.name ? file.name : v4();
};
// 洗稿
const startConfuse = async () => {
// currentConfuseId.value = v4();
......@@ -291,81 +173,10 @@ export const processTextCallback = () => {
openConfuseInterval(`${userInfo.value.id}-${live_task_id.value}`);
};
// 阿里云上传成功回调
const uploadSuccess = (name: string, url: string) => {
// console.log(url, '阿里云上传后的');
alyList.value.push([
{
content: url,
},
]);
};
// 循环上传阿里云
const uploadToAly = async (fileList: File[]) => {
// 每次上传前清空数组
alyList.value = [];
console.log('任务数');
console.log(fileList.length);
// 获取阿里云配置
let config = await getUploadConfig();
for (let i = 0; i < fileList.length; i++) {
let file = fileList[i];
let retryNum = 0;
while (true) {
if (retryNum >= 5) {
console.log('音频块已经重试5次,跳过');
break;
}
if (retryNum) {
config = await getUploadConfig();
}
try {
// 上传阿里云
await alyOssUpload(config, file, uploadSuccess, () => false, getFileName(file));
} catch (e) {
if (e && e.status == 'error') {
// 重新上传
console.log('重新上传');
retryNum += 1;
continue;
}
}
break;
}
}
// 上传完毕
return alyList.value;
};
// 音频合并切割
const audioStart = async (list: any[], dimensional: boolean = true) => {
let file = await audioMerge(list);
if (file) {
// 开始切割
let split_list = await splitAudio(file, 300);
// 合并后的文件上传
if (split_list && split_list.length) {
let result = await uploadToAly(split_list);
console.log('上传完毕');
// 是否一维数组
if (dimensional) {
console.log(result);
return result;
} else {
console.log([result]);
return [result];
}
}
} else {
console.log('没有文件');
}
};
// 重新生成直播
const regenerate = async (list: any[], successCallback: boolean) => {
try {
let params = filterFiled();
let params = filterFiled(getCreateLiveInfo());
params.type_content = list;
let res: any = await liveTaskRegenerate(live_task_id.value, params);
if (res.code == 0) {
......@@ -376,6 +187,10 @@ export const processTextCallback = () => {
}
}
} catch (e) {
writeLog({
name: 'old 重新生成直播-error',
value: e,
});
console.log(e);
}
};
......@@ -463,9 +278,26 @@ export const processTextCallback = () => {
});
// 提交
await submit(type);
// 需要洗稿
if (createLiveInfo.value[createLiveKeys.isDisorganize]) {
await startConfuse();
if (createLiveVersion === 'v1') {
await startConfuse();
} else if (createLiveVersion === 'v2') {
// 异步执行
store.dispatch('asyncCreateLive/confuse', {
user_id: userInfo.value.id,
live_task_id: live_task_id.value,
// 洗稿id
task_id: `${userInfo.value.id}-${live_task_id.value}`,
// 音频任务回调uid
audio_task_id: v4(),
createLiveInfo: ecursionDeepCopy(createLiveInfo.value),
});
//
loading.value = false;
submitSuccessed();
}
} else {
console.log('不用洗稿');
loading.value = false;
......@@ -483,6 +315,10 @@ export const processTextCallback = () => {
if (data && data.audio_address) {
audio_list.push(data.audio_address);
} else {
writeLog({
naem: 'useScript-洗稿缺少参数',
value: data,
});
show_message('洗稿缺少参数');
}
});
......@@ -499,6 +335,10 @@ export const processTextCallback = () => {
}
}
} catch (e) {
writeLog({
name: 'useScript getTaskStatus-error',
value: e,
});
console.log(e);
}
};
......@@ -531,7 +371,6 @@ export const processTextCallback = () => {
currentSetp,
live_task_id,
openInterval,
filterFiled,
initCreateStore,
submit,
submitSuccessed,
......@@ -541,5 +380,6 @@ export const processTextCallback = () => {
currentStartConfuse,
audioStart,
uploadToAly,
getCreateLiveInfo,
};
};
......@@ -14,6 +14,7 @@ import { useRoute } from 'vue-router';
import { callPyjsInWindow, injectWindow } from '@/utils/pyqt';
import { getliveTaskReply, getUserCookie } from '@/utils/api/userApi';
import { useStore } from 'vuex';
import { writeLog } from '@/utils/pyqt';
// 互动回复
......@@ -155,6 +156,10 @@ const mergeCallback = (params: any) => {
addVideo.value = params.add_video;
}
} catch (e) {
writeLog({
name: 'mergeCallback error',
value: e,
});
console.log(e);
}
};
......
......@@ -32,6 +32,7 @@ import useConfuse from '@/hooks/useConfuse';
import { CONFUSE_STATUS } from '@/service/Live';
import { processTextCallback } from '@/hooks/useScript';
import { scriptTypeText } from '@/service/CreateLive';
import { writeLog } from '@/utils/pyqt';
const { currentConfuseId, confuseList, currentStartConfuse, openConfuseInterval } = useConfuse();
const { openInterval: confuseInterval } = processTextCallback();
......@@ -375,6 +376,10 @@ const getLive = async () => {
addVideoList.value = addVideoList.value.concat(res.data);
}
} catch (e) {
writeLog({
name: 'getliveTaskReply 获取直播互动失败',
value: e,
});
console.log(e);
}
};
......@@ -395,6 +400,10 @@ const regenerate = async (list: any[]) => {
console.log('重新生成直播,已提交');
}
} catch (e) {
writeLog({
name: 'only live regenerate error',
value: e,
});
console.log(e);
}
};
......@@ -497,6 +506,10 @@ const getDetail = async (type: string = '') => {
}
}
} catch (e) {
writeLog({
name: '获取直播链接失败',
value: e,
});
console.log(e);
}
};
......@@ -523,7 +536,11 @@ const submitVideo = () => {
show_message('empty-1 py');
}
} catch (e) {
show_message(e.message);
console.log(e);
writeLog({
name: 'only submitVideo error',
value: e,
});
}
};
......@@ -575,6 +592,10 @@ const mergeCallback = (params: any) => {
console.log(params);
}
} catch (e) {
writeLog({
name: 'only mergeCallback error',
value: e,
});
console.log(e);
}
};
......
......@@ -83,12 +83,12 @@ import {
getFile,
} from '@/utils/tool';
import { useStore } from 'vuex';
import { createLiveKeys, scriptTypeText, scriptTypePhonetics, mergeSameAudio } from '@/service/CreateLive';
import { createLiveKeys, scriptTypeText, scriptTypePhonetics, mergeSameAudio, filterFiled } from '@/service/CreateLive';
import { getLiveTaskInfo, createDrafts, getDraftsDetail, liveTts, createLiveTask } from '@/utils/api/userApi';
import { useRoute, onBeforeRouteLeave } from 'vue-router';
import routerConfig from '@/router/tool';
import { onUpdateLiveTask } from '@/service/Common';
import { callPyjsInWindow } from '@/utils/pyqt';
import { callPyjsInWindow, writeLog } from '@/utils/pyqt';
import { useLiveInfoSubmit } from '@/hooks/useStoreCommit';
import { processTextCallback } from '@/hooks/useScript';
import CustomException from '@/utils/error';
......@@ -101,7 +101,7 @@ const {
live_task_id,
audioStart,
openInterval,
filterFiled,
getCreateLiveInfo,
submitSuccessed,
uploadToAly,
} = processTextCallback();
......@@ -275,6 +275,10 @@ const getEditInfo = async (id: any, type: string) => {
}
}
} catch (e) {
writeLog({
name: 'createLive getEditInfo error',
value: e,
});
console.log(e);
}
};
......@@ -356,7 +360,7 @@ const onSave = () => {
// 保存为草稿
const onSaveDrafts = async () => {
let params = filterFiled();
let params = filterFiled(getCreateLiveInfo());
try {
loading.value = true;
let res: any = await createDrafts(params);
......@@ -379,7 +383,7 @@ const editAudioSave = async () => {
try {
loading.value = true;
await audioSplit();
let params = filterFiled();
let params = filterFiled(getCreateLiveInfo());
let res: any = await onUpdateLiveTask(route.query.id, params);
if (res) {
if (route.query.type === 'edit') {
......@@ -392,6 +396,10 @@ const editAudioSave = async () => {
}
loading.value = false;
} catch (e) {
writeLog({
name: 'createLive editAudioSave error',
value: e,
});
loading.value = false;
console.log(e);
}
......@@ -508,7 +516,7 @@ const audioSubmit = async () => {
if (route.query.type == 'edit_drafts') {
type = 'edit_drafts';
}
let params = filterFiled(type);
let params = filterFiled(getCreateLiveInfo(), type);
let res: any = await createLiveTask(params);
if (res.code == 0) {
console.log('创建成功-', res.data.id);
......@@ -517,6 +525,10 @@ const audioSubmit = async () => {
}
loading.value = false;
} catch (e) {
writeLog({
name: 'createLive audioSubmit error',
value: e,
});
loading.value = false;
console.log(e);
}
......
......@@ -7,8 +7,11 @@ import {
updateDrafts,
} from '@/utils/api/userApi';
import { typeTones, typeSoundColor } from '@/service/CreateLive';
import { show_message } from '@/utils/tool';
import { show_message, alyOssUpload } from '@/utils/tool';
import { LIVE_AUDIT_STATUS } from './Live';
import { audioMerge, splitAudio } from '@/utils/audio';
import { v4 } from 'uuid';
import { writeLog } from '@/utils/pyqt';
// 阿里云上传配置
export const getUploadConfig = async () => {
......@@ -112,6 +115,10 @@ export const onUpdateLiveTask = async (id: any, data: any) => {
}
return false;
} catch (e) {
writeLog({
name: 'common onUpdateLiveTask error',
value: e,
});
console.log(e);
return false;
}
......@@ -127,7 +134,87 @@ export const onUpdateDrafts = async (id: any, data: any) => {
}
return false;
} catch (e) {
writeLog({
name: 'common onUpdateDrafts error',
value: e,
});
console.log(e);
return false;
}
};
// 音频合并切割
export const audioStart = async (list: any[], dimensional: boolean = true) => {
let file = await audioMerge(list);
if (file) {
// 开始切割
let split_list = await splitAudio(file, 300);
// 合并后的文件上传
if (split_list && split_list.length) {
let result = await uploadToAly(split_list);
console.log('上传完毕');
// 是否一维数组
if (dimensional) {
console.log(result);
return result;
} else {
console.log([result]);
return [result];
}
}
} else {
console.log('没有文件');
}
};
// 循环上传阿里云
export const uploadToAly = async (fileList: File[]) => {
// 获取文件名
const getFileName = (file: any) => {
return file.name ? file.name : v4();
};
const uploadSuccess = (name: string, url: string) => {
alyList.push([
{
content: url,
},
]);
};
// 每次上传前清空数组
let alyList = [];
console.log('任务数');
console.log(fileList.length);
// 获取阿里云配置
let config = await getUploadConfig();
for (let i = 0; i < fileList.length; i++) {
let file = fileList[i];
let retryNum = 0;
while (true) {
if (retryNum >= 5) {
console.log('音频块已经重试5次,跳过');
break;
}
if (retryNum) {
config = await getUploadConfig();
}
try {
// 上传阿里云
await alyOssUpload(config, file, uploadSuccess, () => false, getFileName(file));
} catch (e) {
writeLog({
name: 'common uploadToAly.alyOssUpload error',
value: e,
});
if (e && e.status == 'error') {
// 重新上传
console.log('重新上传');
retryNum += 1;
continue;
}
}
break;
}
}
// 上传完毕
return alyList;
};
import { mergedArray } from '@/utils/tool';
import { mergedArray, isDev, show_message, dimensionalConvert, DataType } from '@/utils/tool';
import { liveContentRegenerateCallback, liveTts, getLiveTtsCallback, liveTaskRegenerate } from '@/utils/api/userApi';
import { audioStart } from '@/service/Common';
import store from '@/store';
import { v4 } from 'uuid';
import { writeLog } from '@/utils/pyqt';
/**
* 创建直播的版本
* v1-同步执行,直到洗稿和提交完毕
* v2-异步执行
*/
export const createLiveVersion = 'v2';
// 创建直播时提交的变量名
export const createLiveKeys = {
id_type: 'id_type', // 数字人库类型(数字人库和我的数字人)
......@@ -50,3 +63,306 @@ export const mergeSameAudio = (content: any[]) => {
};
});
};
// 获取洗稿回调
export const onRewriteCallback = async (id: string) => {
return new Promise<any[]>((resolve) => {
let interval = null;
console.log('开启轮询,洗稿回调');
// 关闭定时器
const closeConfuseInterval = () => {
window.clearInterval(interval);
clearInterval(interval);
interval = null;
};
// 回调方法
const currentStartConfuseBack = async (id: any) => {
try {
let res: any = await liveContentRegenerateCallback({
task_id: id,
});
if (isDev()) {
//
res.data = [
{
content: `
大家好!欢迎来到今天的直播!我是你们的主持人,今天我将为大家带来一场精彩的直播节目。在这里,我们将分享一些有趣的内容,并回答你们的问题。
首先,让我们来聊一聊今天的主题。今天我们将重点聚焦在XX领域(根据直播主题填写),这是一个非常热门、有趣且前沿的领域。我们将了解最新的发展动态、分享一些实用的技巧,并回答你们提出的问题。
对于新加入直播的朋友,特别欢迎你们!如果你们有任何问题或者想要了解更多关于XX的信息,请随时在评论区留言,我将尽力回答你们的问题。
在这里,我们鼓励大家积极互动。请大家在评论区留下你们的想法、观点和问题。我会选择一些与主题相关的问题进行回答,在回答问题时我会尽量深入浅出,以确保每个人都能够理解。
也请大家相互尊重,遵守礼貌。如果有令人不舒服的言论或者不适当的内容,请及时举报,我们会及时处理。
接下来,让我们一起进入今天的正题吧!不管你是刚开始接触XX,还是已经有一定了解,请相信你们在这里能够获得更多知识、更多的收获。
再次感谢大家的到来和支持,让我们一起度过这个精彩的时刻!祝愿大家在本次直播中有所收获,也希望大家能够在评论区互相交流,共同进步。
谢谢大家!现在,让我们开始今天的直播吧!
`,
},
];
}
if (res.code == 0 && res.data.length) {
console.log('洗稿回调成功');
closeConfuseInterval();
// 返回值
resolve(res.data);
} else {
console.log('洗稿还没有回调', id);
console.log(res.data);
}
} catch (e) {
writeLog({
name: 'service onRewriteCallback.currentStartConfuseBack error',
value: e,
});
console.log(e);
}
};
// 打开定时器
interval = window.setInterval(() => {
currentStartConfuseBack(id);
}, 3000);
});
};
// 提交音频任务
export const submitAudioTask = async (list: any[], item: any, uuid: string) => {
try {
for (let i = 0; i < list.length; i++) {
let params = {
// 音色
phonetic_timbres_id: item[createLiveKeys.textSoundColor],
// 音调
tone_id: item[createLiveKeys.textTones],
content: list[i].content,
uuid: uuid,
};
// 生成音频
await liveTts(params);
}
console.log('等待音频生成完成');
return true;
} catch (e) {
// 日志
writeLog({
name: 'service 提交音频任务失败',
value: e,
});
console.log(e);
return false;
}
// 开始轮询
// openInterval(true, '', true, currentConfuseId.value, false, list.length);
};
// 过滤必要的字段
export const filterFiled = (item: any, type: string = '') => {
// 过滤必须字段
let params: any = {};
params.name = store.getters['live/getName'];
// 数字人id
params.digital_man_id = item[createLiveKeys.id];
// 是否洗稿
params.is_disorganize = item[createLiveKeys.isDisorganize];
// 脚本类型
params.type = item[createLiveKeys.scriptType];
// 脚本内容
if (item[createLiveKeys.scriptType] == scriptTypeText) {
// 文本
params.type_content = item[createLiveKeys.textScriptValue];
// 转换格式
// 先二维转一维
params.type_content = dimensionalConvert(params.type_content);
let list = [];
params.type_content.forEach((item: any) => {
list.push([item]);
});
params.type_content = list;
console.log(params.type_content, '文本 type_content');
// 音色id
params.phonetic_timbres_id = item[createLiveKeys.textSoundColor];
// 文本内容--先转一维数组
let newList = dimensionalConvert(item[createLiveKeys.textScriptList]);
params.content = newList.map((row: any) => {
return {
title: row.title,
content: row.content,
};
});
} else {
// 切割后的音频格式
const audioConversion = (list: any[]) => {
return list
.map((child: any) => {
return child.audio_url;
})
.join('|');
};
// 音频
params.type_content = item[createLiveKeys.audioScriptList].map((audioScript: any) => {
let list = [];
audioScript.data.forEach((it: any) => {
let params: any = {
content: '',
old_content: '',
name: '',
uuid: v4(),
duration: 0,
};
if (it.duration) {
params.duration = parseInt(it.duration);
}
// 草稿类型的
if (type == 'edit_drafts') {
if (it.children && it.children.length > 1) {
// 有切割的
params.content = audioConversion(it.children);
}
if (it.old_content) {
params.old_content = it.old_content;
} else if (it.url) {
params.old_content = it.url;
}
if (it.content) {
params.content = it.content;
} else if (it.url) {
params.content = it.url;
}
} else {
// 获取编辑状态下的content
if (it.children && it.children.length > 1) {
// 修改content
params.content = audioConversion(it.children);
params.old_content = it.audio_url;
} else {
if (typeof it === 'string') {
params.content = it;
params.old_content = it;
} else if (it.url) {
params.content = it.url;
params.old_content = it.url;
} else {
params.content = it.audio_url;
params.old_content = it.audio_url;
}
}
}
// 切割后的
if (typeof it !== 'string' && it.new_content) {
params.content = it.new_content;
}
// 获取文件名
if (!DataType(it, 'string') && DataType(it, 'object')) {
if (it.name) {
params.name = it.name;
} else if (it.file && it.file.name) {
params.name = it.file.name;
}
}
list.push(params);
});
return list;
});
console.log(params.type_content, '音频 type_content');
// 音色id
params.phonetic_timbres_id = item[createLiveKeys.phoneticsSoundColor];
}
// 音调id
params.tone_id = item[createLiveKeys.textTones];
// 互动库
params.interaction_ids = item[createLiveKeys.interactiveLibrary];
return params;
};
export const regenerate = async (list: any[], item: any, live_id: any) => {
try {
let params = filterFiled(item);
params.type_content = list;
let res: any = await liveTaskRegenerate(live_id, params);
if (res.code == 0) {
console.log(JSON.stringify(params));
writeLog('重新生成直播,已经提交-' + live_id);
console.log('重新生成直播,已经提交-', live_id);
}
} catch (e) {
writeLog({
name: 'service createLive regenerate error',
value: e,
});
console.log(e);
}
};
// 洗稿获取音频回调
export const getAudioCallback = (audio_task_id: string, len: number, liveInfo: any, live_id: any) => {
let interval = null;
// 关闭定时器
const closeInterval = () => {
window.clearInterval(interval);
clearInterval(interval);
interval = null;
};
const getTaskStatus = async () => {
try {
let res: any = await getLiveTtsCallback({
task_id: audio_task_id,
});
if (res.code == 0) {
if (isDev()) {
let params = {
data: {
audio_address:
'http://nls-cloud-cn-shanghai.oss-cn-shanghai.aliyuncs.com/jupiter-flow/tmp/e56d8750eb3a44f9930f73703489acb1.wav?Expires=1692087730&OSSAccessKeyId=LTAIUpwNp2H7pBG5&Signature=FtKSld5Dn55po9GyTm%2BefRKmPqw%3D',
task_id: 0,
},
};
for (let i = 0; i < 3; i++) {
res.data.push(params);
}
}
if (res.data.length) {
console.log('音频任务回调成功');
console.log(res.data);
if (res.data.length >= len) {
closeInterval();
let audio_list = [];
// 洗稿任务
res.data.forEach((item: any) => {
let data = item.data;
if (data && data.audio_address) {
audio_list.push(data.audio_address);
} else {
console.log('洗稿缺少参数');
show_message('洗稿缺少参数');
}
});
let resultList = await audioStart(audio_list, true);
// 提交
await regenerate(resultList, liveInfo, live_id);
}
}
}
} catch (e) {
writeLog({
name: 'service createLive getTaskStatus error',
value: e,
});
console.log(e);
}
};
interval = window.setInterval(() => {
getTaskStatus();
}, 3000);
};
......@@ -5,6 +5,7 @@ import theme from './modules/theme';
import language from './modules/language';
import live from './modules/live';
import navbar from './modules/navbar';
import asyncCreateLive from './modules/asyncCreateLive';
export const store = createStore({
modules: {
......@@ -14,6 +15,7 @@ export const store = createStore({
language,
live,
navbar,
asyncCreateLive,
},
});
......
import { onRewriteCallback, submitAudioTask, getAudioCallback } from '@/service/CreateLive';
import { writeLog } from '@/utils/pyqt';
const state = {
language: '',
};
type StateType = typeof state;
const mutations = {
// setLang(state: StateType, info: string) {
// state.language = info;
// // 设置html 属性
// document.documentElement.setAttribute('lang', info);
// },
};
const getters = {
// getLang: (state: StateType) => {
// return state.language;
// },
};
const actions = {
// 洗稿
async confuse({ commit }, params) {
const { user_id, live_task_id, task_id, audio_task_id, createLiveInfo } = params;
try {
// 获取洗稿回调
let confuseList = await onRewriteCallback(task_id);
// 提交音频任务
let status = await submitAudioTask(confuseList, createLiveInfo, audio_task_id);
if (status) {
// 打开音频回调轮询
getAudioCallback(audio_task_id, confuseList.length, createLiveInfo, live_task_id);
}
} catch (e) {
writeLog({
name: 'dispatch confuse error',
value: e,
});
console.log(e);
}
},
};
export default {
namespaced: true,
state,
mutations,
actions,
getters,
};
import audiobufferToWav from 'audiobuffer-to-wav';
import request from '@/utils/upLoadRequest';
import { writeLog } from '@/utils/pyqt';
export const createAudioContext = () => {
return new (window.AudioContext || window.webkitAudioContext)();
......@@ -82,14 +83,16 @@ export async function audioMerge(filePaths) {
offset += Math.round(buffer.duration * sampleRate);
});
console.log(buffers);
console.log('zxl');
// 导出合并后的音频数据为 WAV 文件
const mergedData = exportBufferAsWav(mergedBuffer);
console.log('通过了');
const blob = new Blob([mergedData], { type: 'audio/wav' });
console.log('合并完成', blob);
return blob;
} catch (error) {
writeLog({
name: '音频合并失败',
value: error,
});
console.error('音频文件合并失败:', error);
}
}
......
import axios from 'axios';
import { MessagePlugin } from 'tdesign-vue-next';
import { writeLog } from './pyqt';
const instance: any = axios.create({
timeout: 60 * 60 * 1000,
......@@ -19,7 +20,9 @@ instance.interceptors.response.use(
if (data.code === 0) {
return data;
} else {
MessagePlugin.error(data.msg || '请求错误');
let message = data.msg || '请求错误';
MessagePlugin.error(message);
writeLog(message);
return Promise.reject(data.msg);
}
},
......@@ -28,9 +31,13 @@ instance.interceptors.response.use(
if ('response' in err) {
const { message: msg } = err.response.data;
if (err.response.data.indexOf('<Code>UserDisable</Code>') !== -1) {
MessagePlugin.error('阿里云可能欠费');
let message = '阿里云可能欠费';
MessagePlugin.error(message);
writeLog(message);
} else {
MessagePlugin.error(msg || '请求错误');
let message = msg || '请求错误';
MessagePlugin.error(message);
writeLog(message);
}
return err.response;
}
......
......@@ -40,6 +40,17 @@ export const callPyjsInWindow = (name: string, value: any = '', callback: boolea
}
return window.pyjs[name](JSON.stringify(value));
} catch (e) {
writeLog({
name: 'call python error',
value: e,
});
console.error(e);
}
};
// 写入日志
export const writeLog = (value: any) => {
if (window.pyjs && window.pyjs['writeLog']) {
window.pyjs['writeLog'](JSON.stringify(value));
}
};
......@@ -2,7 +2,7 @@ import axios from 'axios';
import { store } from '@/store/index';
import router from '@/router';
import { show_message, isDev } from './tool';
import { callPyjsInWindow } from './pyqt';
import { callPyjsInWindow, writeLog } from './pyqt';
const error_messaage = '请求错误';
......@@ -55,6 +55,7 @@ instance.interceptors.response.use(
if ('response' in err && err['response']) {
const { status, data } = err.response;
if (status == 401) {
writeLog('登录信息已失效');
router.push({
path: '/login',
});
......@@ -63,12 +64,15 @@ instance.interceptors.response.use(
store.commit('user/removeUserInfo');
return;
}
show_message(data.message || error_messaage, 'error');
let message = data.message || error_messaage;
show_message(message, 'error');
writeLog(message);
return err.response;
} else {
// 格式不一致的
let res = err.toJSON();
show_message(res.message, 'error');
writeLog(res.message);
return;
}
},
......
import { MessagePlugin, RequestMethodResponse } from 'tdesign-vue-next';
import request from '@/utils/upLoadRequest';
import { writeLog } from './pyqt';
// import JSZip from 'jszip';
// import { saveAs } from 'file-saver';
......@@ -249,6 +250,10 @@ export const alyOssUpload = (
}
} catch (e) {
console.log(e);
writeLog({
name: 'tool aly upload error',
value: e,
});
reject({
status: 'error',
response: '',
......
import axios from 'axios';
import { writeLog } from './pyqt';
const instance: any = axios.create({
timeout: 60 * 60 * 1000,
......@@ -18,11 +19,25 @@ instance.interceptors.response.use(
if (data.code === 0) {
return data;
}
// 状态不对的
writeLog({
name: 'upLoad request status error',
value: response,
});
},
(err) => {
console.log(err);
if ('response' in err) {
writeLog({
name: 'upLoad request status error',
value: err.response,
});
return err.response;
} else {
writeLog({
name: 'upLoad request status error',
value: err,
});
}
},
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment