From a105cfa9ff0b18f0ff5b84ac659fc11caf5d1b26 Mon Sep 17 00:00:00 2001 From: liugaowei Date: Sun, 7 May 2023 13:45:56 +0800 Subject: [PATCH] =?UTF-8?q?1.9.2=20=E6=B7=BB=E5=8A=A0=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 +- .vscode/.debug.script.mjs | 23 ------ .vscode/extensions.json | 6 -- .vscode/launch.json | 44 ---------- .vscode/settings.json | 12 --- .vscode/tasks.json | 30 ------- package.json | 2 +- src/store/store.ts | 169 +++++++++++++++++++++++++------------- 8 files changed, 116 insertions(+), 174 deletions(-) delete mode 100644 .vscode/.debug.script.mjs delete mode 100644 .vscode/extensions.json delete mode 100644 .vscode/launch.json delete mode 100644 .vscode/settings.json delete mode 100644 .vscode/tasks.json diff --git a/.gitignore b/.gitignore index 02f2500..f01b450 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ dist-ssr *.local # Editor directories and files +.vscode .idea .DS_Store *.suo @@ -22,5 +23,4 @@ dist-ssr *.sw? release -.vscode/.debug.env -.vscode/settings.json + diff --git a/.vscode/.debug.script.mjs b/.vscode/.debug.script.mjs deleted file mode 100644 index 1d68c8f..0000000 --- a/.vscode/.debug.script.mjs +++ /dev/null @@ -1,23 +0,0 @@ -import fs from 'fs' -import path from 'path' -import { fileURLToPath } from 'url' -import { createRequire } from 'module' -import { spawn } from 'child_process' - -const pkg = createRequire(import.meta.url)('../package.json') -const __dirname = path.dirname(fileURLToPath(import.meta.url)) - -// write .debug.env -const envContent = Object.entries(pkg.env).map(([key, val]) => `${key}=${val}`) -fs.writeFileSync(path.join(__dirname, '.debug.env'), envContent.join('\n')) - -// bootstrap -spawn( - // TODO: terminate `npm run dev` when Debug exits. - process.platform === 'win32' ? 'npm.cmd' : 'npm', - ['run', 'dev'], - { - stdio: 'inherit', - env: Object.assign(process.env, { VSCODE_DEBUG: 'true' }), - }, -) diff --git a/.vscode/extensions.json b/.vscode/extensions.json deleted file mode 100644 index 232ead7..0000000 --- a/.vscode/extensions.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "recommendations": [ - "Vue.volar", - "Vue.vscode-typescript-vue-plugin" - ] -} diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 52ac762..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "compounds": [ - { - "name": "Debug App", - "preLaunchTask": "Before Debug", - "configurations": [ - "Debug Main Process", - "Debug Renderer Process" - ], - "presentation": { - "hidden": false, - "group": "", - "order": 1 - }, - "stopAll": true - } - ], - "configurations": [ - { - "name": "Debug Main Process", - "type": "pwa-node", - "request": "launch", - "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron", - "windows": { - "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd" - }, - "runtimeArgs": [ - "--remote-debugging-port=9229", - "." - ], - "envFile": "${workspaceFolder}/.vscode/.debug.env" - }, - { - "name": "Debug Renderer Process", - "port": 9229, - "request": "attach", - "type": "pwa-chrome" - }, - ] -} diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 1bd320e..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "typescript.tsdk": "node_modules/typescript/lib", - "typescript.enablePromptUseWorkspaceTsdk": true, - "cSpell.words": [ - "customvoiceconnectionid", - "KHTML", - "mstts", - "southeastasia", - "ssml", - "uuidv" - ] -} diff --git a/.vscode/tasks.json b/.vscode/tasks.json deleted file mode 100644 index a1bf353..0000000 --- a/.vscode/tasks.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - // See https://go.microsoft.com/fwlink/?LinkId=733558 - // for the documentation about the tasks.json format - "version": "2.0.0", - "tasks": [ - { - "label": "Before Debug", - "type": "shell", - "command": "node .vscode/.debug.script.mjs", - "isBackground": true, - "problemMatcher": { - "owner": "typescript", - "fileLocation": "relative", - "pattern": { - "regexp": "^([a-zA-Z]\\:\/?([\\w\\-]\/?)+\\.\\w+):(\\d+):(\\d+): (ERROR|WARNING)\\: (.*)$", - "file": 1, - "line": 3, - "column": 4, - "code": 5, - "message": 6 - }, - "background": { - "activeOnStart": true, - "beginsPattern": "^.*building for development.*$", - "endsPattern": "built in [0-9]*ms.*$", - } - } - } - ] -} diff --git a/package.json b/package.json index f2ca5e4..f5e4499 100644 --- a/package.json +++ b/package.json @@ -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 ", diff --git a/src/store/store.ts b/src/store/store.ts index 2e8c4f7..9e47d23 100644 --- a/src/store/store.ts +++ b/src/store/store.ts @@ -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"单文本转换 @@ -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 { // 字数少直接转换 @@ -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" 批量转换 @@ -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", "字数过多,正在对文本切片。。。"); @@ -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( @@ -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, + }); }); } }