LaiTool V3.0.1-preview.6
This commit is contained in:
parent
e85b0a986d
commit
07f99708da
1
.gitignore
vendored
1
.gitignore
vendored
@ -18,6 +18,7 @@ resources/scripts/virtual py
|
|||||||
resources/scripts/_internal
|
resources/scripts/_internal
|
||||||
resources/logger
|
resources/logger
|
||||||
resources/scripts/Temp
|
resources/scripts/Temp
|
||||||
|
resources/scripts/db
|
||||||
*scripts/db*
|
*scripts/db*
|
||||||
resources/image/Temp*
|
resources/image/Temp*
|
||||||
resources/package/ffmpeg/w*
|
resources/package/ffmpeg/w*
|
||||||
|
|||||||
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "laitool",
|
"name": "laitool",
|
||||||
"version": "3.0.1-preview.5",
|
"version": "3.0.1-preview.6",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "laitool",
|
"name": "laitool",
|
||||||
"version": "3.0.1-preview.5",
|
"version": "3.0.1-preview.6",
|
||||||
"hasInstallScript": true,
|
"hasInstallScript": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@alicloud/alimt20181012": "^1.2.0",
|
"@alicloud/alimt20181012": "^1.2.0",
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "laitool",
|
"name": "laitool",
|
||||||
"version": "3.0.1-preview.5",
|
"version": "3.0.1-preview.6",
|
||||||
"description": "An AI tool for image processing, video processing, and other functions.",
|
"description": "An AI tool for image processing, video processing, and other functions.",
|
||||||
"main": "./out/main/index.js",
|
"main": "./out/main/index.js",
|
||||||
"author": "laitool.cn",
|
"author": "laitool.cn",
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@ -232,40 +232,72 @@ export class TTS {
|
|||||||
const parts = text.match(
|
const parts = text.match(
|
||||||
/[^,。!?;:“”()《》,.!?;:"()<>$$$$\n]+[,。!?;:“”()《》,.!?;:"()<>$$$$\n]*/g
|
/[^,。!?;:“”()《》,.!?;:"()<>$$$$\n]+[,。!?;:“”()《》,.!?;:"()<>$$$$\n]*/g
|
||||||
);
|
);
|
||||||
|
|
||||||
// 初始化 SRT 内容
|
// 初始化 SRT 内容
|
||||||
let srtContent = "";
|
let srtContent = "";
|
||||||
let index = 1;
|
let index = 1;
|
||||||
|
|
||||||
// 函数用于去掉文本末尾的标点符号
|
// 函数用于去掉文本末尾的标点符号
|
||||||
const removeTrailingPunctuation = (text: string) => {
|
const removeTrailingPunctuation = (text) => {
|
||||||
return text.replace(/[\s,。!?;:“”()《》,.!?;:"()<>$$$$]+$/, "");
|
return text.replace(/[\s,。!?;:“”()《》,.!?;:"()\n]+$/, "");
|
||||||
};
|
};
|
||||||
|
|
||||||
// 配对时间轴和文案分段
|
// 函数用于将毫秒格式化为 SRT 时间格式
|
||||||
|
const formatTime = (ms) => {
|
||||||
|
const date = new Date(ms);
|
||||||
|
const hours = String(date.getUTCHours()).padStart(2, "0");
|
||||||
|
const minutes = String(date.getUTCMinutes()).padStart(2, "0");
|
||||||
|
const seconds = String(date.getUTCSeconds()).padStart(2, "0");
|
||||||
|
const milliseconds = String(date.getUTCMilliseconds()).padStart(3, "0");
|
||||||
|
return `${hours}:${minutes}:${seconds},${milliseconds}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
// 合并文本和时间轴
|
||||||
|
let combinedPart = "";
|
||||||
|
let startTime = null;
|
||||||
|
let endTime = null;
|
||||||
|
let j = 0;
|
||||||
|
let count = 0;
|
||||||
|
|
||||||
for (let i = 0; i < parts.length; i++) {
|
for (let i = 0; i < parts.length; i++) {
|
||||||
const part = parts[i];
|
let partText = removeTrailingPunctuation(parts[i].trim());
|
||||||
let startTime =
|
// partText = partText.trim()
|
||||||
srtJson[i * 2]?.start || srtJson[srtJson.length - 1].start;
|
let tempText = partText.replaceAll(' ', '');
|
||||||
let endTime =
|
for (; j < srtJson.length; j++) {
|
||||||
srtJson[i * 2 + 1]?.end || srtJson[srtJson.length - 1].end;
|
let timePart = srtJson[j].part;
|
||||||
|
timePart = removeTrailingPunctuation(timePart.trim());
|
||||||
|
|
||||||
// 去掉文案末尾的标点符号
|
if (tempText.includes(timePart)) {
|
||||||
const cleanedPart = removeTrailingPunctuation(part.trim());
|
// 如果匹配到,合并文本片段并更新结束时间
|
||||||
|
combinedPart += timePart;
|
||||||
|
if (startTime === null) {
|
||||||
|
startTime = srtJson[j].start; // 设置开始时间
|
||||||
|
}
|
||||||
|
endTime = srtJson[j].end; // 更新结束时间
|
||||||
|
|
||||||
// 将时间格式化为 SRT 格式
|
// 如果下一个文本片段开始匹配下一个标点,则跳出内层循环
|
||||||
const formatTime = (ms) => {
|
if (combinedPart == tempText) {
|
||||||
const date = new Date(ms);
|
j++; // 准备下一次对比从下一个时间片段开始
|
||||||
const hours = String(date.getUTCHours()).padStart(2, "0");
|
break;
|
||||||
const minutes = String(date.getUTCMinutes()).padStart(2, "0");
|
}
|
||||||
const seconds = String(date.getUTCSeconds()).padStart(2, "0");
|
} else {
|
||||||
const milliseconds = String(date.getUTCMilliseconds()).padStart(3, "0");
|
j++; // 准备下一次对比从下一个时间片段开始
|
||||||
return `${hours}:${minutes}:${seconds},${milliseconds}`;
|
break;
|
||||||
};
|
}
|
||||||
|
count++;
|
||||||
|
console.log(count);
|
||||||
|
count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// 生成 SRT 片段
|
// 生成SRT段落
|
||||||
srtContent += `${index}\n${formatTime(startTime)} --> ${formatTime(
|
srtContent += `${index}\n${formatTime(startTime)} --> ${formatTime(
|
||||||
endTime
|
endTime
|
||||||
)}\n${cleanedPart}\n\n`;
|
)}\n${partText}\n\n`;
|
||||||
|
|
||||||
|
// 重置变量
|
||||||
|
combinedPart = "";
|
||||||
|
startTime = null;
|
||||||
|
endTime = null;
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user