Skip to content

Commit

Permalink
1.9.2 添加异常提示
Browse files Browse the repository at this point in the history
  • Loading branch information
liugaowei committed May 7, 2023
1 parent 755b815 commit a105cfa
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 174 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dist-ssr
*.local

# Editor directories and files
.vscode
.idea
.DS_Store
*.suo
Expand All @@ -22,5 +23,4 @@ dist-ssr
*.sw?

release
.vscode/.debug.env
.vscode/settings.json

23 changes: 0 additions & 23 deletions .vscode/.debug.script.mjs

This file was deleted.

6 changes: 0 additions & 6 deletions .vscode/extensions.json

This file was deleted.

44 changes: 0 additions & 44 deletions .vscode/launch.json

This file was deleted.

12 changes: 0 additions & 12 deletions .vscode/settings.json

This file was deleted.

30 changes: 0 additions & 30 deletions .vscode/tasks.json

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tts-vue",
"version": "1.9.1",
"version": "1.9.2",
"main": "dist/electron/main/index.js",
"description": "🎤 微软语音合成工具,使用 Electron + Vue + ElementPlus + Vite 构建。",
"author": "沫離Loker <[email protected]>",
Expand Down
169 changes: 113 additions & 56 deletions src/store/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export const useTtsStore = defineStore("ttsStore", {
},
async start() {
console.log("清空缓存中");
let resFlag = true;
this.currMp3Buffer = Buffer.alloc(0);
this.currMp3Url = "";
// this.page.asideIndex == "1"单文本转换
Expand Down Expand Up @@ -150,28 +151,50 @@ export const useTtsStore = defineStore("ttsStore", {
textHandler.res.push(textHandler.buffer.join(""));
const tasks = textHandler.res;
for (let index = 0; index < tasks.length; index++) {
ipcRenderer.send("log.info", `正在执行第${index + 1}次转换。。。`);
const element = tasks[index];
value.inputValue = element;
const buffers: any = await getTTSData(
value,
this.formConfig.voiceSelect,
this.formConfig.voiceStyleSelect,
this.formConfig.role,
(this.formConfig.speed - 1) * 100,
(this.formConfig.pitch - 1) * 50
);
this.currMp3Buffer = Buffer.concat([this.currMp3Buffer, buffers]);
ipcRenderer.send(
"log.info",
`第${index + 1}次转换完成,此时Buffer长度为:${
this.currMp3Buffer.length
}`
);
try {
ipcRenderer.send(
"log.info",
`正在执行第${index + 1}次转换。。。`
);
const element = tasks[index];
value.inputValue = element;
const buffers: any = await getTTSData(
value,
this.formConfig.voiceSelect,
this.formConfig.voiceStyleSelect,
this.formConfig.role,
(this.formConfig.speed - 1) * 100,
(this.formConfig.pitch - 1) * 50
);
this.currMp3Buffer = Buffer.concat([this.currMp3Buffer, buffers]);
ipcRenderer.send(
"log.info",
`第${index + 1}次转换完成,此时Buffer长度为:${
this.currMp3Buffer.length
}`
);
} catch (error) {
resFlag = false;
console.error(error);
ipcRenderer.send("log.error", error);
this.isLoading = false;
ElMessage({
message: "网络异常!\n" + String(error),
type: "error",
duration: 3000,
});
if (this.currMp3Buffer.length > 0) {
const svlob = new Blob([this.currMp3Buffer]);
this.currMp3Url = URL.createObjectURL(svlob);
}
return;
}
}

const svlob = new Blob([this.currMp3Buffer]);
this.currMp3Url = URL.createObjectURL(svlob);
if (this.currMp3Buffer.length > 0) {
const svlob = new Blob([this.currMp3Buffer]);
this.currMp3Url = URL.createObjectURL(svlob);
}
this.isLoading = false;
} else {
// 字数少直接转换
Expand All @@ -190,17 +213,26 @@ export const useTtsStore = defineStore("ttsStore", {
this.isLoading = false;
})
.catch((err) => {
resFlag = false;
this.isLoading = false;
console.log(err);
console.error(err);
ElMessage({
message: "转换失败\n" + String(err),
type: "error",
duration: 2000,
});
});
}
ElMessage({
message: this.config.autoplay
? "成功,正在试听~"
: "成功,请手动播放。",
type: "success",
duration: 2000,
});
if (resFlag) {
ElMessage({
message: this.config.autoplay
? "成功,正在试听~"
: "成功,请手动播放。",
type: "success",
duration: 2000,
});
}

ipcRenderer.send("log.info", `转换完成`);
} else {
// this.page.asideIndex == "2" 批量转换
Expand Down Expand Up @@ -228,7 +260,7 @@ export const useTtsStore = defineStore("ttsStore", {
let buffer = Buffer.alloc(0);

if (datastr.length > 400) {
const delimiters = ",。?,.?".split("");
const delimiters = ",。?,.? ".split("");
const maxSize = 300;
ipcRenderer.send("log.info", "字数过多,正在对文本切片。。。");

Expand All @@ -254,36 +286,56 @@ export const useTtsStore = defineStore("ttsStore", {
textHandler.res.push(textHandler.buffer.join(""));
const tasks = textHandler.res;
for (let index = 0; index < tasks.length; index++) {
ipcRenderer.send(
"log.info",
`正在执行第${index + 1}次转换。。。`
);
const element = tasks[index];
inps.inputValue = element;
const buffers: any = await getTTSData(
inps,
this.formConfig.voiceSelect,
this.formConfig.voiceStyleSelect,
this.formConfig.role,
(this.formConfig.speed - 1) * 100,
(this.formConfig.pitch - 1) * 50
);
buffer = Buffer.concat([buffer, buffers]);
ipcRenderer.send(
"log.info",
`第${index + 1}次转换完成,此时Buffer长度为:${
buffer.length
}`
);
try {
ipcRenderer.send(
"log.info",
`正在执行第${index + 1}次转换。。。`
);
const element = tasks[index];
inps.inputValue = element;
const buffers: any = await getTTSData(
inps,
this.formConfig.voiceSelect,
this.formConfig.voiceStyleSelect,
this.formConfig.role,
(this.formConfig.speed - 1) * 100,
(this.formConfig.pitch - 1) * 50
);
buffer = Buffer.concat([buffer, buffers]);
ipcRenderer.send(
"log.info",
`第${index + 1}次转换完成,此时Buffer长度为:${
buffer.length
}`
);
} catch (error) {
console.error(error);
resFlag = false;
ipcRenderer.send("log.error", error);
this.isLoading = false;
ElMessage({
message: "转换失败\n" + String(error),
type: "error",
duration: 3000,
});
if (buffer.length > 0) {
fs.writeFileSync(filePath, buffer);
this.setDoneStatus(item.filePath);
}
return;
}
}

fs.writeFileSync(filePath, buffer);
this.setDoneStatus(item.filePath);
ElMessage({
message: "成功,正在写入" + filePath,
type: "success",
duration: 2000,
});
if (resFlag) {
ElMessage({
message: "成功,正在写入" + filePath,
type: "success",
duration: 2000,
});
}

this.isLoading = false;
} else {
await getTTSData(
Expand All @@ -306,7 +358,12 @@ export const useTtsStore = defineStore("ttsStore", {
})
.catch((err) => {
this.isLoading = false;
console.log(err);
console.error(err);
ElMessage({
message: "转换失败\n" + String(err),
type: "error",
duration: 3000,
});
});
}
}
Expand Down

0 comments on commit a105cfa

Please sign in to comment.