Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
ai_fundub
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
template admin
ai_fundub
Commits
5665c6f3
Commit
5665c6f3
authored
Sep 21, 2026
by
Jeff nan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat
parent
a8393ce7
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
678 additions
and
99 deletions
+678
-99
index.css
form/index.css
+84
-0
index.html
form/index.html
+81
-91
index.js
form/index.js
+513
-8
No files found.
form/index.css
View file @
5665c6f3
...
@@ -306,6 +306,90 @@
...
@@ -306,6 +306,90 @@
min-height
:
200px
;
min-height
:
200px
;
}
}
.sentence-edit-row
{
margin-bottom
:
8px
;
}
.sentence-edit-row
.el-textarea__inner
{
font-size
:
15px
;
line-height
:
1.45
;
color
:
#303133
;
}
.sentence-edit-row--zh
.el-textarea__inner
{
color
:
#606266
;
}
/* 波形图微调 */
.waveform-tune-meta
{
display
:
flex
;
justify-content
:
space-between
;
gap
:
12px
;
margin-bottom
:
12px
;
color
:
#606266
;
font-size
:
13px
;
}
.waveform-tune-canvas-wrap
{
position
:
relative
;
width
:
100%
;
height
:
160px
;
border-radius
:
8px
;
overflow
:
hidden
;
cursor
:
ew-resize
;
user-select
:
none
;
background
:
#1f2933
;
}
.waveform-tune-canvas
{
display
:
block
;
width
:
100%
;
height
:
160px
;
}
.waveform-tune-selection
{
position
:
absolute
;
top
:
0
;
bottom
:
0
;
background
:
rgba
(
64
,
158
,
255
,
0.18
);
pointer-events
:
none
;
z-index
:
1
;
}
.waveform-tune-handle
{
position
:
absolute
;
top
:
0
;
bottom
:
0
;
width
:
2px
;
margin-left
:
-1px
;
z-index
:
2
;
pointer-events
:
none
;
}
.waveform-tune-handle--start
{
background
:
#67c23a
;
}
.waveform-tune-handle--end
{
background
:
#f56c6c
;
}
.waveform-tune-handle
span
{
position
:
absolute
;
top
:
6px
;
left
:
50%
;
transform
:
translateX
(
-50%
);
padding
:
1px
6px
;
border-radius
:
3px
;
font-size
:
12px
;
color
:
#fff
;
white-space
:
nowrap
;
pointer-events
:
none
;
}
.waveform-tune-handle--start
span
{
background
:
#67c23a
;
}
.waveform-tune-handle--end
span
{
background
:
#f56c6c
;
}
.waveform-tune-error
{
margin-top
:
12px
;
color
:
#f56c6c
;
font-size
:
13px
;
line-height
:
1.5
;
}
/* 提示包裹,保证禁用按钮仍可触发 tooltip */
/* 提示包裹,保证禁用按钮仍可触发 tooltip */
.disabled-tip
{
.disabled-tip
{
display
:
inline-block
;
display
:
inline-block
;
...
...
form/index.html
View file @
5665c6f3
...
@@ -213,7 +213,8 @@
...
@@ -213,7 +213,8 @@
:show-close=
"false"
:show-close=
"false"
:close-on-click-modal=
"false"
:close-on-click-modal=
"false"
:destroy-on-close=
"true"
:destroy-on-close=
"true"
@
open=
"onSubtitleEditorOpen"
>
@
open=
"onSubtitleEditorOpen"
@
close=
"stopSentencePreview"
>
<span
slot=
"title"
class=
"dialog-title subtitle-editor-title"
>
<span
slot=
"title"
class=
"dialog-title subtitle-editor-title"
>
<el-page-header
<el-page-header
@
back=
"confirmExitSubtitleEditor"
@
back=
"confirmExitSubtitleEditor"
...
@@ -226,6 +227,7 @@
...
@@ -226,6 +227,7 @@
@
click=
"overwriteAndRegenerateLyrics"
@
click=
"overwriteAndRegenerateLyrics"
>
覆盖上传并重新生成歌词
</el-button>
>
覆盖上传并重新生成歌词
</el-button>
</span>
</span>
<audio
ref=
"sentencePreviewAudio"
preload=
"auto"
style=
"display:none;"
></audio>
<div
<div
class=
"subtitle-editor-body"
class=
"subtitle-editor-body"
v-loading=
"subtitleEditorLoading"
v-loading=
"subtitleEditorLoading"
...
@@ -242,7 +244,7 @@
...
@@ -242,7 +244,7 @@
>
>
<el-card
shadow=
"never"
body-style=
"padding:12px;"
>
<el-card
shadow=
"never"
body-style=
"padding:12px;"
>
<div
style=
"display:flex; align-items:center; color:#909399; font-size:12px; margin-bottom:4px;"
>
<div
style=
"display:flex; align-items:center; color:#909399; font-size:12px; margin-bottom:4px;"
>
<div
style=
"display:flex; align-items:center; gap:8px;"
>
<div
style=
"display:flex; align-items:center; gap:8px;
flex-wrap:wrap;
"
>
<span>
#{{ item.index }}
</span>
<span>
#{{ item.index }}
</span>
<span
class=
"time-edit-line"
>
<span
class=
"time-edit-line"
>
<span>
{{ item.start }}
</span>
<span>
{{ item.start }}
</span>
...
@@ -260,100 +262,42 @@
...
@@ -260,100 +262,42 @@
></i>
></i>
</span>
</span>
<el-button
<el-button
v-if=
"idx > 0"
size=
"mini"
:type=
"previewPlayingIndex === idx ? 'danger' : 'success'"
@
click=
"previewSentence(idx)"
>
{{ previewPlayingIndex === idx ? '停止' : '试听' }}
</el-button>
<el-button
size=
"mini"
size=
"mini"
type=
"primary"
type=
"primary"
plain
@
click=
"insertSentenceAfter(idx)"
@
click=
"mergeWithPrevious(idx)"
>
添加
</el-button>
:disabled=
"isAnyTaskRunning()"
<el-button
>
与上一句合并
</el-button>
</div>
</div>
<div
style=
"display:flex; align-items:center; gap:8px; font-size:16px; margin-bottom:4px;"
>
<span
style=
"display:block; line-height:1.05; margin:0; padding:0;"
>
{{ buildSentenceFromWords(item.sWordsRef) }}
</span>
</div>
<div
style=
"display:flex; align-items:center; gap:8px; font-size:16px; margin-bottom:4px;"
>
<span
style=
"display:block; line-height:1.05; margin:0; padding:0; margin-top:-2px; color:#909399;"
>
{{ buildSentenceFromTranslatedItems(item.tItemsRef) }}
</span>
</div>
<div
style=
"display:flex; gap:12px; margin-top:8px; flex-wrap:wrap;"
>
<div
style=
"flex:1; min-width:300px;"
>
<div
style=
"font-weight:500; margin-bottom:4px;"
>
原文分词
</div>
<el-table
class=
"swords-table"
:data=
"item.sWordsRef || []"
size=
"mini"
size=
"mini"
border
type=
"danger"
:row-class-name=
"({row, rowIndex}) => getSWordsRowClass(item, idx, row, rowIndex)"
@
click=
"deleteSentence(idx)"
@
cell-mouse-enter=
"(row, column, cell, event) => onSWordsCellEnter(idx, row, column, cell, event)"
>
删除
</el-button>
@
cell-mouse-leave=
"(row, column, cell, event) => onSWordsCellLeave(idx, row, column, cell, event)"
<el-button
>
size=
"mini"
<el-table-column
label=
"start"
width=
"130"
>
type=
"warning"
<template
slot-scope=
"s"
>
@
click=
"openWaveformTune(idx)"
<div
class=
"swords-start-cell"
>
>
预览波形图微调
</el-button>
<span
class=
"time-edit-line"
>
<span>
{{ formatTimeNumeric(s.row.start) }}
</span>
<i
class=
"el-icon-edit time-edit-icon"
title=
"编辑分词开始时间"
@
click=
"openTimeEdit({ type: 'word-start', tlIndex: idx, wordIndex: s.$index })"
></i>
</span>
<el-tooltip
v-if=
"item._hoveredSIndex === s.$index && !isAnyTaskRunning() && s.$index < (item.sWordsRef ? item.sWordsRef.length - 1 : 0)"
content=
"在此处拆分为两句"
placement=
"left"
>
<span
class=
"row-split-trigger"
@
click=
"splitAtSWordsRow(idx, s.$index)"
>
拆
</span>
</el-tooltip>
</div>
</div>
</template>
</el-table-column>
<el-table-column
label=
"end"
width=
"130"
>
<template
slot-scope=
"s"
>
<span
class=
"time-edit-line"
>
<span>
{{ formatTimeNumeric(s.row.end) }}
</span>
<i
class=
"el-icon-edit time-edit-icon"
title=
"编辑分词结束时间"
@
click=
"openTimeEdit({ type: 'word-end', tlIndex: idx, wordIndex: s.$index })"
></i>
</span>
</template>
</el-table-column>
<el-table-column
label=
"word"
>
<template
slot-scope=
"s"
>
<el-input
v-model=
"s.row.word"
size=
"mini"
></el-input>
</template>
</el-table-column>
</el-table>
</div>
</div>
<div
style=
"flex:1; min-width:300px;"
>
<div
class=
"sentence-edit-row"
>
<div
style=
"font-weight:500; margin-bottom:4px;"
>
翻译
</div>
<el-input
<el-table
:data=
"item.tItemsRef || []"
size=
"mini"
border
>
type=
"textarea"
<el-table-column
label=
"start"
width=
"90"
>
:autosize=
"{ minRows: 1, maxRows: 6 }"
<template
slot-scope=
"t"
>
v-model=
"item.subtitleText"
{{ formatTimeNumeric(t.row.start) }}
placeholder=
"英文原文"
</template>
></el-input>
</el-table-column>
<el-table-column
label=
"end"
width=
"90"
>
<template
slot-scope=
"t"
>
{{ formatTimeNumeric(t.row.end) }}
</template>
</el-table-column>
<el-table-column
label=
"text"
>
<template
slot-scope=
"t"
>
<el-input
v-model=
"t.row.text"
size=
"mini"
></el-input>
</template>
</el-table-column>
</el-table>
</div>
</div>
<div
class=
"sentence-edit-row sentence-edit-row--zh"
>
<el-input
type=
"textarea"
:autosize=
"{ minRows: 1, maxRows: 6 }"
v-model=
"item.translatedTranslated"
placeholder=
"中文翻译"
></el-input>
</div>
</div>
</el-card>
</el-card>
</el-timeline-item>
</el-timeline-item>
...
@@ -411,6 +355,52 @@
...
@@ -411,6 +355,52 @@
<el-button
size=
"small"
type=
"primary"
@
click=
"confirmTimeEdit"
>
确定
</el-button>
<el-button
size=
"small"
type=
"primary"
@
click=
"confirmTimeEdit"
>
确定
</el-button>
</span>
</span>
</el-dialog>
</el-dialog>
<!-- 波形图微调弹窗 -->
<el-dialog
title=
"波形图微调"
:visible
.
sync=
"waveformDialog.visible"
width=
"780px"
append-to-body
:close-on-click-modal=
"false"
custom-class=
"waveform-tune-dialog"
@
closed=
"onWaveformDialogClosed"
>
<div
v-loading=
"waveformDialog.loading"
element-loading-text=
"正在加载波形..."
>
<div
class=
"waveform-tune-meta"
>
<span>
窗口:{{ formatTime(waveformDialog.windowStart) }} ~ {{ formatTime(waveformDialog.windowEnd) }}
</span>
<span>
选中:{{ formatTime(waveformDialog.startSec) }} ~ {{ formatTime(waveformDialog.endSec) }}
</span>
</div>
<div
class=
"waveform-tune-canvas-wrap"
ref=
"waveformWrap"
@
mousedown=
"onWaveformPointerDown"
>
<canvas
ref=
"waveformCanvas"
class=
"waveform-tune-canvas"
></canvas>
<div
class=
"waveform-tune-handle waveform-tune-handle--start"
:style=
"{ left: waveformStartPct + '%' }"
>
<span>
开始
</span>
</div>
<div
class=
"waveform-tune-handle waveform-tune-handle--end"
:style=
"{ left: waveformEndPct + '%' }"
>
<span>
结束
</span>
</div>
<div
class=
"waveform-tune-selection"
:style=
"{ left: waveformStartPct + '%', width: Math.max(0, waveformEndPct - waveformStartPct) + '%' }"
></div>
</div>
<div
v-if=
"waveformDialog.error"
class=
"waveform-tune-error"
>
{{ waveformDialog.error }}
</div>
</div>
<span
slot=
"footer"
class=
"dialog-footer"
>
<el-button
size=
"small"
@
click=
"cancelWaveformTune"
>
取消
</el-button>
<el-button
size=
"small"
type=
"primary"
:disabled=
"!!waveformDialog.loading || !!waveformDialog.error"
@
click=
"confirmWaveformTune"
>
确定
</el-button>
</span>
</el-dialog>
</div>
</div>
</div>
</div>
</body>
</body>
...
...
form/index.js
View file @
5665c6f3
...
@@ -95,6 +95,35 @@ function initVueApp(savedData) {
...
@@ -95,6 +95,35 @@ function initVueApp(savedData) {
maxInclusive
:
true
,
maxInclusive
:
true
,
boundHint
:
''
,
boundHint
:
''
,
},
},
// 句子试听
previewPlayingIndex
:
-
1
,
// 波形图微调
waveformDialog
:
{
visible
:
false
,
loading
:
false
,
error
:
''
,
tlIndex
:
null
,
windowStart
:
0
,
windowEnd
:
0
,
startSec
:
0
,
endSec
:
0
,
peaks
:
[],
dragging
:
null
,
// 'start' | 'end'
},
},
computed
:
{
waveformStartPct
()
{
const
d
=
this
.
waveformDialog
;
const
span
=
d
.
windowEnd
-
d
.
windowStart
;
if
(
!
span
||
span
<=
0
)
return
0
;
return
((
d
.
startSec
-
d
.
windowStart
)
/
span
)
*
100
;
},
waveformEndPct
()
{
const
d
=
this
.
waveformDialog
;
const
span
=
d
.
windowEnd
-
d
.
windowStart
;
if
(
!
span
||
span
<=
0
)
return
100
;
return
((
d
.
endSec
-
d
.
windowStart
)
/
span
)
*
100
;
},
},
},
mounted
()
{
mounted
()
{
// 如果有保存的数据,恢复状态
// 如果有保存的数据,恢复状态
...
@@ -133,6 +162,11 @@ function initVueApp(savedData) {
...
@@ -133,6 +162,11 @@ function initVueApp(savedData) {
clearInterval
(
this
.
vocalPollTimer
);
clearInterval
(
this
.
vocalPollTimer
);
this
.
vocalPollTimer
=
null
;
this
.
vocalPollTimer
=
null
;
}
}
this
.
stopSentencePreview
&&
this
.
stopSentencePreview
();
this
.
unbindWaveformDragListeners
&&
this
.
unbindWaveformDragListeners
();
if
(
this
.
_previewAudioCtx
&&
this
.
_previewAudioCtx
.
close
)
{
try
{
this
.
_previewAudioCtx
.
close
();
}
catch
(
e
)
{}
}
},
},
methods
:
{
methods
:
{
// 是否有任一任务在进行中(按钮禁用统一判断)
// 是否有任一任务在进行中(按钮禁用统一判断)
...
@@ -677,14 +711,476 @@ function initVueApp(savedData) {
...
@@ -677,14 +711,476 @@ function initVueApp(savedData) {
cancelButtonText
:
'
取消
'
,
cancelButtonText
:
'
取消
'
,
type
:
'
warning
'
,
type
:
'
warning
'
,
});
});
this
.
stopSentencePreview
();
this
.
subtitleEditorVisible
=
false
;
this
.
subtitleEditorVisible
=
false
;
}
catch
(
e
)
{
}
catch
(
e
)
{
// 用户取消,无需处理
// 用户取消,无需处理
}
}
},
},
// 试听媒体源:优先字幕结果里的音频,否则用原视频
getPreviewMediaSrc
()
{
const
audioUrl
=
this
.
subtitlesResult
&&
this
.
subtitlesResult
.
audioUrl
;
if
(
audioUrl
)
return
String
(
audioUrl
).
replace
(
/^http:
\/\/
/i
,
'
https://
'
);
if
(
this
.
videoUrl
)
return
String
(
this
.
videoUrl
).
replace
(
/^http:
\/\/
/i
,
'
https://
'
);
return
''
;
},
// 停止句子试听
stopSentencePreview
()
{
const
audio
=
this
.
$refs
.
sentencePreviewAudio
;
if
(
audio
)
{
try
{
audio
.
pause
();
}
catch
(
e
)
{}
if
(
this
.
_previewTimeUpdate
)
{
audio
.
removeEventListener
(
'
timeupdate
'
,
this
.
_previewTimeUpdate
);
this
.
_previewTimeUpdate
=
null
;
}
if
(
this
.
_previewEnded
)
{
audio
.
removeEventListener
(
'
ended
'
,
this
.
_previewEnded
);
this
.
_previewEnded
=
null
;
}
}
this
.
previewPlayingIndex
=
-
1
;
},
// 试听某一句:播放 start ~ end
async
previewSentence
(
idx
)
{
if
(
this
.
previewPlayingIndex
===
idx
)
{
this
.
stopSentencePreview
();
return
;
}
const
item
=
this
.
subtitleEditor
.
mergedList
&&
this
.
subtitleEditor
.
mergedList
[
idx
];
if
(
!
item
)
return
;
const
startSec
=
this
.
parseTimeToSeconds
(
item
.
start
);
const
endSec
=
this
.
parseTimeToSeconds
(
item
.
end
);
if
(
isNaN
(
startSec
)
||
isNaN
(
endSec
)
||
endSec
<=
startSec
)
{
this
.
$message
.
warning
(
'
该句时间无效,无法试听
'
);
return
;
}
const
src
=
this
.
getPreviewMediaSrc
();
if
(
!
src
)
{
this
.
$message
.
warning
(
'
暂无可用音视频,无法试听
'
);
return
;
}
this
.
stopSentencePreview
();
const
audio
=
this
.
$refs
.
sentencePreviewAudio
;
if
(
!
audio
)
return
;
const
needReload
=
!
audio
.
src
||
audio
.
getAttribute
(
'
data-src
'
)
!==
src
;
if
(
needReload
)
{
audio
.
src
=
src
;
audio
.
setAttribute
(
'
data-src
'
,
src
);
try
{
await
new
Promise
((
resolve
,
reject
)
=>
{
const
onReady
=
()
=>
{
cleanup
();
resolve
();
};
const
onErr
=
()
=>
{
cleanup
();
reject
(
new
Error
(
'
load failed
'
));
};
const
cleanup
=
()
=>
{
audio
.
removeEventListener
(
'
canplay
'
,
onReady
);
audio
.
removeEventListener
(
'
error
'
,
onErr
);
};
audio
.
addEventListener
(
'
canplay
'
,
onReady
);
audio
.
addEventListener
(
'
error
'
,
onErr
);
audio
.
load
();
});
}
catch
(
e
)
{
this
.
$message
.
error
(
'
音频加载失败
'
);
return
;
}
}
this
.
previewPlayingIndex
=
idx
;
try
{
audio
.
currentTime
=
Math
.
max
(
0
,
startSec
);
}
catch
(
e
)
{}
this
.
_previewTimeUpdate
=
()
=>
{
if
(
audio
.
currentTime
>=
endSec
-
0.03
)
{
this
.
stopSentencePreview
();
}
};
this
.
_previewEnded
=
()
=>
{
this
.
stopSentencePreview
();
};
audio
.
addEventListener
(
'
timeupdate
'
,
this
.
_previewTimeUpdate
);
audio
.
addEventListener
(
'
ended
'
,
this
.
_previewEnded
);
try
{
await
audio
.
play
();
}
catch
(
e
)
{
console
.
error
(
e
);
this
.
$message
.
error
(
'
播放失败
'
);
this
.
stopSentencePreview
();
}
},
// 在当前句后面插入一组空句子
insertSentenceAfter
(
idx
)
{
const
list
=
this
.
subtitleEditor
.
mergedList
;
if
(
!
Array
.
isArray
(
list
)
||
!
list
[
idx
])
return
;
const
curr
=
list
[
idx
];
const
next
=
list
[
idx
+
1
];
const
startSec
=
this
.
parseTimeToSeconds
(
curr
.
end
);
let
endSec
=
next
?
this
.
parseTimeToSeconds
(
next
.
start
)
:
startSec
+
1
;
if
(
isNaN
(
startSec
))
{
this
.
$message
.
warning
(
'
当前句结束时间无效,无法插入
'
);
return
;
}
if
(
isNaN
(
endSec
)
||
endSec
<=
startSec
)
{
endSec
=
startSec
+
0.5
;
}
const
startStr
=
this
.
formatTime
(
startSec
);
const
endStr
=
this
.
formatTime
(
endSec
);
const
newItem
=
{
index
:
idx
+
2
,
sIndex
:
null
,
tIndex
:
null
,
start
:
startStr
,
end
:
endStr
,
subtitleText
:
''
,
subtitleWordString
:
''
,
translatedText
:
''
,
translatedTranslated
:
''
,
translatedItemsString
:
''
,
sWordsRef
:
[],
tItemsRef
:
[],
};
list
.
splice
(
idx
+
1
,
0
,
newItem
);
list
.
forEach
((
it
,
i
)
=>
{
it
.
index
=
i
+
1
;
});
if
(
this
.
previewPlayingIndex
>
idx
)
{
this
.
previewPlayingIndex
+=
1
;
}
this
.
$message
.
success
(
'
已在本句后插入一组
'
);
},
// 删除当前这组句子
deleteSentence
(
idx
)
{
const
list
=
this
.
subtitleEditor
.
mergedList
;
if
(
!
Array
.
isArray
(
list
)
||
!
list
[
idx
])
return
;
if
(
list
.
length
<=
1
)
{
this
.
$message
.
warning
(
'
至少保留一句,无法删除
'
);
return
;
}
if
(
this
.
previewPlayingIndex
===
idx
)
{
this
.
stopSentencePreview
();
}
else
if
(
this
.
previewPlayingIndex
>
idx
)
{
this
.
previewPlayingIndex
-=
1
;
}
list
.
splice
(
idx
,
1
);
list
.
forEach
((
it
,
i
)
=>
{
it
.
index
=
i
+
1
;
});
this
.
$message
.
success
(
'
已删除本组
'
);
},
// 打开波形图微调
async
openWaveformTune
(
idx
)
{
const
list
=
this
.
subtitleEditor
.
mergedList
;
const
item
=
list
&&
list
[
idx
];
if
(
!
item
)
return
;
const
startSec
=
this
.
parseTimeToSeconds
(
item
.
start
);
const
endSec
=
this
.
parseTimeToSeconds
(
item
.
end
);
if
(
isNaN
(
startSec
)
||
isNaN
(
endSec
)
||
endSec
<=
startSec
)
{
this
.
$message
.
warning
(
'
该句时间无效,无法微调
'
);
return
;
}
if
(
!
this
.
getPreviewMediaSrc
())
{
this
.
$message
.
warning
(
'
暂无可用音视频,无法加载波形
'
);
return
;
}
this
.
stopSentencePreview
();
this
.
waveformDialog
.
visible
=
true
;
this
.
waveformDialog
.
loading
=
true
;
this
.
waveformDialog
.
error
=
''
;
this
.
waveformDialog
.
tlIndex
=
idx
;
this
.
waveformDialog
.
windowStart
=
Math
.
max
(
0
,
startSec
-
1
);
this
.
waveformDialog
.
windowEnd
=
endSec
+
1
;
this
.
waveformDialog
.
startSec
=
startSec
;
this
.
waveformDialog
.
endSec
=
endSec
;
this
.
waveformDialog
.
peaks
=
[];
this
.
waveformDialog
.
dragging
=
null
;
try
{
const
buffer
=
await
this
.
ensurePreviewAudioBuffer
();
const
duration
=
buffer
.
duration
||
0
;
if
(
duration
>
0
&&
this
.
waveformDialog
.
windowEnd
>
duration
)
{
this
.
waveformDialog
.
windowEnd
=
duration
;
}
if
(
this
.
waveformDialog
.
endSec
>
this
.
waveformDialog
.
windowEnd
)
{
this
.
waveformDialog
.
endSec
=
this
.
waveformDialog
.
windowEnd
;
}
this
.
waveformDialog
.
peaks
=
this
.
buildWaveformPeaks
(
buffer
,
this
.
waveformDialog
.
windowStart
,
this
.
waveformDialog
.
windowEnd
,
500
);
this
.
$nextTick
(()
=>
{
this
.
drawWaveformCanvas
();
this
.
bindWaveformDragListeners
();
});
}
catch
(
e
)
{
console
.
error
(
e
);
this
.
waveformDialog
.
error
=
'
波形加载失败(可能是音视频跨域限制),请检查 audioUrl / videoUrl 的 CORS 配置
'
;
}
finally
{
this
.
waveformDialog
.
loading
=
false
;
this
.
$nextTick
(()
=>
this
.
drawWaveformCanvas
());
}
},
async
ensurePreviewAudioBuffer
()
{
const
src
=
this
.
getPreviewMediaSrc
();
if
(
!
src
)
throw
new
Error
(
'
no media src
'
);
if
(
this
.
_previewAudioBuffer
&&
this
.
_previewAudioBufferSrc
===
src
)
{
return
this
.
_previewAudioBuffer
;
}
const
resp
=
await
fetch
(
src
,
{
mode
:
'
cors
'
,
cache
:
'
force-cache
'
});
if
(
!
resp
.
ok
)
throw
new
Error
(
'
fetch failed:
'
+
resp
.
status
);
const
arr
=
await
resp
.
arrayBuffer
();
const
Ctx
=
window
.
AudioContext
||
window
.
webkitAudioContext
;
if
(
!
Ctx
)
throw
new
Error
(
'
AudioContext unsupported
'
);
if
(
!
this
.
_previewAudioCtx
)
this
.
_previewAudioCtx
=
new
Ctx
();
const
buffer
=
await
this
.
_previewAudioCtx
.
decodeAudioData
(
arr
.
slice
(
0
));
this
.
_previewAudioBuffer
=
buffer
;
this
.
_previewAudioBufferSrc
=
src
;
return
buffer
;
},
buildWaveformPeaks
(
buffer
,
windowStart
,
windowEnd
,
barCount
=
400
)
{
const
channel
=
buffer
.
getChannelData
(
0
);
const
sampleRate
=
buffer
.
sampleRate
;
const
startSample
=
Math
.
max
(
0
,
Math
.
floor
(
windowStart
*
sampleRate
));
const
endSample
=
Math
.
min
(
channel
.
length
,
Math
.
ceil
(
windowEnd
*
sampleRate
));
const
total
=
Math
.
max
(
1
,
endSample
-
startSample
);
const
peaks
=
new
Array
(
barCount
);
for
(
let
i
=
0
;
i
<
barCount
;
i
++
)
{
const
s
=
startSample
+
Math
.
floor
((
i
/
barCount
)
*
total
);
const
e
=
startSample
+
Math
.
floor
(((
i
+
1
)
/
barCount
)
*
total
);
let
max
=
0
;
for
(
let
j
=
s
;
j
<
e
;
j
++
)
{
const
v
=
Math
.
abs
(
channel
[
j
]);
if
(
v
>
max
)
max
=
v
;
}
peaks
[
i
]
=
max
;
}
return
peaks
;
},
drawWaveformCanvas
()
{
const
canvas
=
this
.
$refs
.
waveformCanvas
;
const
wrap
=
this
.
$refs
.
waveformWrap
;
if
(
!
canvas
||
!
wrap
)
return
;
const
dpr
=
window
.
devicePixelRatio
||
1
;
const
width
=
Math
.
max
(
320
,
wrap
.
clientWidth
||
720
);
const
height
=
160
;
canvas
.
width
=
Math
.
floor
(
width
*
dpr
);
canvas
.
height
=
Math
.
floor
(
height
*
dpr
);
canvas
.
style
.
width
=
width
+
'
px
'
;
canvas
.
style
.
height
=
height
+
'
px
'
;
const
ctx
=
canvas
.
getContext
(
'
2d
'
);
if
(
!
ctx
)
return
;
ctx
.
setTransform
(
dpr
,
0
,
0
,
dpr
,
0
,
0
);
ctx
.
clearRect
(
0
,
0
,
width
,
height
);
ctx
.
fillStyle
=
'
#1f2933
'
;
ctx
.
fillRect
(
0
,
0
,
width
,
height
);
const
peaks
=
this
.
waveformDialog
.
peaks
||
[];
if
(
!
peaks
.
length
)
return
;
const
mid
=
height
/
2
;
const
barW
=
width
/
peaks
.
length
;
let
peakMax
=
0
;
for
(
let
i
=
0
;
i
<
peaks
.
length
;
i
++
)
{
if
(
peaks
[
i
]
>
peakMax
)
peakMax
=
peaks
[
i
];
}
if
(
peakMax
<=
0
)
peakMax
=
1
;
ctx
.
fillStyle
=
'
#5b8def
'
;
for
(
let
i
=
0
;
i
<
peaks
.
length
;
i
++
)
{
const
h
=
(
peaks
[
i
]
/
peakMax
)
*
(
height
*
0.85
);
const
x
=
i
*
barW
;
const
y
=
mid
-
h
/
2
;
ctx
.
fillRect
(
x
,
y
,
Math
.
max
(
1
,
barW
*
0.7
),
h
);
}
},
waveformSecFromClientX
(
clientX
)
{
const
wrap
=
this
.
$refs
.
waveformWrap
;
const
d
=
this
.
waveformDialog
;
if
(
!
wrap
)
return
d
.
startSec
;
const
rect
=
wrap
.
getBoundingClientRect
();
const
ratio
=
Math
.
min
(
1
,
Math
.
max
(
0
,
(
clientX
-
rect
.
left
)
/
Math
.
max
(
1
,
rect
.
width
)));
return
d
.
windowStart
+
ratio
*
(
d
.
windowEnd
-
d
.
windowStart
);
},
onWaveformPointerDown
(
e
)
{
if
(
this
.
waveformDialog
.
loading
||
this
.
waveformDialog
.
error
)
return
;
const
wrap
=
this
.
$refs
.
waveformWrap
;
if
(
!
wrap
)
return
;
const
rect
=
wrap
.
getBoundingClientRect
();
const
x
=
e
.
clientX
-
rect
.
left
;
const
startX
=
(
this
.
waveformStartPct
/
100
)
*
rect
.
width
;
const
endX
=
(
this
.
waveformEndPct
/
100
)
*
rect
.
width
;
const
hit
=
10
;
if
(
Math
.
abs
(
x
-
startX
)
<=
hit
)
{
this
.
waveformDialog
.
dragging
=
'
start
'
;
}
else
if
(
Math
.
abs
(
x
-
endX
)
<=
hit
)
{
this
.
waveformDialog
.
dragging
=
'
end
'
;
}
else
{
// 点到空白:靠近哪边拖哪边
this
.
waveformDialog
.
dragging
=
Math
.
abs
(
x
-
startX
)
<=
Math
.
abs
(
x
-
endX
)
?
'
start
'
:
'
end
'
;
this
.
applyWaveformDrag
(
e
.
clientX
);
}
e
.
preventDefault
();
},
applyWaveformDrag
(
clientX
)
{
const
d
=
this
.
waveformDialog
;
if
(
!
d
.
dragging
)
return
;
let
sec
=
this
.
waveformSecFromClientX
(
clientX
);
// 拖拽只限制在波形窗口内,且开始 < 结束;邻句等校验在点确定时再提示
const
minGap
=
0.001
;
sec
=
Math
.
max
(
d
.
windowStart
,
Math
.
min
(
sec
,
d
.
windowEnd
));
if
(
d
.
dragging
===
'
start
'
)
{
d
.
startSec
=
Math
.
min
(
sec
,
d
.
endSec
-
minGap
);
}
else
if
(
d
.
dragging
===
'
end
'
)
{
d
.
endSec
=
Math
.
max
(
sec
,
d
.
startSec
+
minGap
);
}
},
// 波形微调时:按与手动改句子起止相同的规则,计算可拖范围
getProposedSentenceTimeClamp
(
tlIndex
,
proposedStart
,
proposedEnd
)
{
const
list
=
this
.
subtitleEditor
.
mergedList
||
[];
const
item
=
list
[
tlIndex
];
const
prev
=
tlIndex
>
0
?
list
[
tlIndex
-
1
]
:
null
;
const
next
=
tlIndex
<
list
.
length
-
1
?
list
[
tlIndex
+
1
]
:
null
;
const
prevEnd
=
prev
?
this
.
parseTimeToSeconds
(
prev
.
end
)
:
0
;
const
nextStart
=
next
?
this
.
parseTimeToSeconds
(
next
.
start
)
:
Infinity
;
const
words
=
item
&&
Array
.
isArray
(
item
.
sWordsRef
)
?
item
.
sWordsRef
:
[];
// 与 getTimeEditBounds('sentence-start'/'sentence-end') 一致
let
startMin
=
isNaN
(
prevEnd
)
?
0
:
Math
.
max
(
0
,
prevEnd
);
let
startMax
=
proposedEnd
;
// 对应句子 end,互斥
let
endMin
=
proposedStart
;
let
endMax
=
isNaN
(
nextStart
)
?
Infinity
:
nextStart
;
if
(
words
.
length
)
{
const
firstEnd
=
this
.
parseTimeToSeconds
(
words
[
0
].
end
);
const
lastStart
=
this
.
parseTimeToSeconds
(
words
[
words
.
length
-
1
].
start
);
if
(
!
isNaN
(
firstEnd
))
startMax
=
Math
.
min
(
startMax
,
firstEnd
);
if
(
!
isNaN
(
lastStart
))
endMin
=
Math
.
max
(
endMin
,
lastStart
);
}
return
{
startMin
,
startMax
,
startMinInclusive
:
true
,
startMaxInclusive
:
false
,
endMin
,
endMax
,
endMinInclusive
:
false
,
endMaxInclusive
:
true
,
};
},
// 校验拟写入的句子起止,规则与 confirmTimeEdit 中句子起止一致
validateProposedSentenceTimes
(
tlIndex
,
startSec
,
endSec
)
{
if
(
startSec
<
0
)
{
return
{
ok
:
false
,
message
:
'
开始时间不能小于 0
'
};
}
if
(
!
(
endSec
>
startSec
))
{
return
{
ok
:
false
,
message
:
'
结束时间必须大于开始时间
'
};
}
const
list
=
this
.
subtitleEditor
.
mergedList
||
[];
const
item
=
list
[
tlIndex
];
if
(
!
item
)
return
{
ok
:
false
,
message
:
'
目标句子不存在
'
};
const
EPS
=
1
e
-
6
;
const
c
=
this
.
getProposedSentenceTimeClamp
(
tlIndex
,
startSec
,
endSec
);
// start 边界(同 sentence-start)
if
(
isFinite
(
c
.
startMin
))
{
if
(
c
.
startMinInclusive
?
startSec
+
EPS
<
c
.
startMin
:
startSec
<=
c
.
startMin
+
EPS
)
{
return
{
ok
:
false
,
message
:
`开始时间不合法,需
${
this
.
formatBoundLabel
(
c
.
startMin
,
c
.
startMinInclusive
,
true
)}
`
};
}
}
if
(
isFinite
(
c
.
startMax
))
{
if
(
c
.
startMaxInclusive
?
startSec
-
EPS
>
c
.
startMax
:
startSec
>=
c
.
startMax
-
EPS
)
{
return
{
ok
:
false
,
message
:
`开始时间不合法,需
${
this
.
formatBoundLabel
(
c
.
startMax
,
c
.
startMaxInclusive
,
false
)}
`
};
}
}
// end 边界(同 sentence-end)
if
(
isFinite
(
c
.
endMin
))
{
if
(
c
.
endMinInclusive
?
endSec
+
EPS
<
c
.
endMin
:
endSec
<=
c
.
endMin
+
EPS
)
{
return
{
ok
:
false
,
message
:
`结束时间不合法,需
${
this
.
formatBoundLabel
(
c
.
endMin
,
c
.
endMinInclusive
,
true
)}
`
};
}
}
if
(
isFinite
(
c
.
endMax
))
{
if
(
c
.
endMaxInclusive
?
endSec
-
EPS
>
c
.
endMax
:
endSec
>=
c
.
endMax
-
EPS
)
{
return
{
ok
:
false
,
message
:
`结束时间不合法,需
${
this
.
formatBoundLabel
(
c
.
endMax
,
c
.
endMaxInclusive
,
false
)}
`
};
}
}
return
{
ok
:
true
};
},
bindWaveformDragListeners
()
{
this
.
unbindWaveformDragListeners
();
this
.
_onWaveformMove
=
(
e
)
=>
{
if
(
!
this
.
waveformDialog
.
dragging
)
return
;
this
.
applyWaveformDrag
(
e
.
clientX
);
};
this
.
_onWaveformUp
=
()
=>
{
this
.
waveformDialog
.
dragging
=
null
;
};
document
.
addEventListener
(
'
mousemove
'
,
this
.
_onWaveformMove
);
document
.
addEventListener
(
'
mouseup
'
,
this
.
_onWaveformUp
);
},
unbindWaveformDragListeners
()
{
if
(
this
.
_onWaveformMove
)
{
document
.
removeEventListener
(
'
mousemove
'
,
this
.
_onWaveformMove
);
this
.
_onWaveformMove
=
null
;
}
if
(
this
.
_onWaveformUp
)
{
document
.
removeEventListener
(
'
mouseup
'
,
this
.
_onWaveformUp
);
this
.
_onWaveformUp
=
null
;
}
},
confirmWaveformTune
()
{
const
d
=
this
.
waveformDialog
;
if
(
d
.
loading
||
d
.
error
)
return
;
const
check
=
this
.
validateProposedSentenceTimes
(
d
.
tlIndex
,
d
.
startSec
,
d
.
endSec
);
if
(
!
check
.
ok
)
{
this
.
$alert
(
check
.
message
||
'
时间不合法
'
,
'
无法保存
'
,
{
type
:
'
warning
'
,
confirmButtonText
:
'
知道了
'
,
});
return
;
}
const
item
=
this
.
subtitleEditor
.
mergedList
&&
this
.
subtitleEditor
.
mergedList
[
d
.
tlIndex
];
if
(
!
item
)
{
this
.
$message
.
error
(
'
目标句子不存在
'
);
return
;
}
item
.
start
=
this
.
formatTime
(
d
.
startSec
);
item
.
end
=
this
.
formatTime
(
d
.
endSec
);
this
.
syncSentenceStartToFirstSegments
(
item
,
d
.
startSec
);
this
.
syncSentenceEndToLastSegments
(
item
,
d
.
endSec
);
d
.
visible
=
false
;
this
.
$message
.
success
(
'
时间已按波形微调更新
'
);
},
cancelWaveformTune
()
{
this
.
waveformDialog
.
visible
=
false
;
},
onWaveformDialogClosed
()
{
this
.
unbindWaveformDragListeners
();
this
.
waveformDialog
.
dragging
=
null
;
this
.
waveformDialog
.
peaks
=
[];
this
.
waveformDialog
.
error
=
''
;
this
.
waveformDialog
.
loading
=
false
;
},
// 弹窗打开时加载数据
// 弹窗打开时加载数据
async
onSubtitleEditorOpen
()
{
async
onSubtitleEditorOpen
()
{
this
.
stopSentencePreview
();
try
{
try
{
this
.
subtitleEditorLoading
=
true
;
this
.
subtitleEditorLoading
=
true
;
const
subtitleUrl
=
(
this
.
subtitlesResult
.
subtitleJsonUrl
||
''
).
replace
(
'
http://
'
,
'
https://
'
);
const
subtitleUrl
=
(
this
.
subtitlesResult
.
subtitleJsonUrl
||
''
).
replace
(
'
http://
'
,
'
https://
'
);
...
@@ -1377,24 +1873,27 @@ function initVueApp(savedData) {
...
@@ -1377,24 +1873,27 @@ function initVueApp(savedData) {
}
}
const
tMatch
=
best
||
{};
const
tMatch
=
best
||
{};
const
sWordsRef
=
s
.
sWordsRef
||
[];
const
tItemsRef
=
tMatch
&&
tMatch
.
tItemsRef
?
tMatch
.
tItemsRef
:
[];
merged
.
push
({
merged
.
push
({
index
:
s
.
sIndex
+
1
,
index
:
s
.
sIndex
+
1
,
sIndex
:
s
.
sIndex
,
sIndex
:
s
.
sIndex
,
tIndex
:
tMatch
.
tIndex
!=
null
?
tMatch
.
tIndex
:
null
,
tIndex
:
tMatch
.
tIndex
!=
null
?
tMatch
.
tIndex
:
null
,
start
:
this
.
formatTime
(
s
.
startSec
),
start
:
this
.
formatTime
(
s
.
startSec
),
end
:
this
.
formatTime
(
s
.
endSec
),
end
:
this
.
formatTime
(
s
.
endSec
),
subtitleText
:
s
.
text
||
''
,
subtitleText
:
this
.
buildSentenceFromWords
(
sWordsRef
)
||
s
.
text
||
''
,
subtitleWordString
:
this
.
safeStringify
(
s
.
word
),
subtitleWordString
:
this
.
safeStringify
(
s
.
word
),
translatedText
:
(
tMatch
.
text
||
''
),
translatedText
:
(
tMatch
.
text
||
''
),
translatedTranslated
:
(
tMatch
.
translated
||
''
),
translatedTranslated
:
this
.
buildSentenceFromTranslatedItems
(
tItemsRef
)
||
(
tMatch
.
translated
||
''
),
translatedItemsString
:
this
.
safeStringify
(
tMatch
&&
tMatch
.
raw
&&
tMatch
.
raw
.
translatedItems
),
translatedItemsString
:
this
.
safeStringify
(
tMatch
&&
tMatch
.
raw
&&
tMatch
.
raw
.
translatedItems
),
sWordsRef
:
s
.
sWordsRef
||
[]
,
sWordsRef
,
tItemsRef
:
tMatch
&&
tMatch
.
tItemsRef
?
tMatch
.
tItemsRef
:
[]
tItemsRef
});
});
}
}
}
else
{
}
else
{
// 以翻译为基准(字幕为空时也能显示时间轴)
// 以翻译为基准(字幕为空时也能显示时间轴)
for
(
const
t
of
tNorm
)
{
for
(
const
t
of
tNorm
)
{
const
tItemsRef
=
t
.
tItemsRef
||
[];
merged
.
push
({
merged
.
push
({
index
:
t
.
tIndex
+
1
,
index
:
t
.
tIndex
+
1
,
sIndex
:
null
,
sIndex
:
null
,
...
@@ -1404,10 +1903,10 @@ function initVueApp(savedData) {
...
@@ -1404,10 +1903,10 @@ function initVueApp(savedData) {
subtitleText
:
''
,
subtitleText
:
''
,
subtitleWordString
:
''
,
subtitleWordString
:
''
,
translatedText
:
(
t
.
text
||
''
),
translatedText
:
(
t
.
text
||
''
),
translatedTranslated
:
(
t
.
translated
||
''
),
translatedTranslated
:
this
.
buildSentenceFromTranslatedItems
(
tItemsRef
)
||
(
t
.
translated
||
''
),
translatedItemsString
:
this
.
safeStringify
(
t
&&
t
.
raw
&&
t
.
raw
.
translatedItems
),
translatedItemsString
:
this
.
safeStringify
(
t
&&
t
.
raw
&&
t
.
raw
.
translatedItems
),
sWordsRef
:
[],
sWordsRef
:
[],
tItemsRef
:
t
.
tItemsRef
||
[]
tItemsRef
});
});
}
}
}
}
...
@@ -1515,11 +2014,14 @@ function initVueApp(savedData) {
...
@@ -1515,11 +2014,14 @@ function initVueApp(savedData) {
const
sStartOut
=
this
.
serializeTimeByFormat
(
sStartSec
,
sFmt
);
const
sStartOut
=
this
.
serializeTimeByFormat
(
sStartSec
,
sFmt
);
const
sEndOut
=
this
.
serializeTimeByFormat
(
sEndSec
,
sFmt
);
const
sEndOut
=
this
.
serializeTimeByFormat
(
sEndSec
,
sFmt
);
const
enText
=
(
typeof
m
.
subtitleText
===
'
string
'
)
?
m
.
subtitleText
:
this
.
buildSentenceFromWords
(
sWords
);
newSList
.
push
({
newSList
.
push
({
start
:
sStartOut
,
start
:
sStartOut
,
end
:
sEndOut
,
end
:
sEndOut
,
words
:
sWords
,
words
:
sWords
,
text
:
this
.
buildSentenceFromWords
(
sWords
)
,
text
:
enText
,
});
});
// 翻译条目 start/end 与句子 start/end 实际对齐
// 翻译条目 start/end 与句子 start/end 实际对齐
...
@@ -1527,11 +2029,14 @@ function initVueApp(savedData) {
...
@@ -1527,11 +2029,14 @@ function initVueApp(savedData) {
const
tEndSec
=
!
isNaN
(
sEndSec
)
?
sEndSec
:
this
.
parseTimeToSeconds
(
tSegs
.
length
?
tSegs
[
tSegs
.
length
-
1
].
end
:
sEndSec
);
const
tEndSec
=
!
isNaN
(
sEndSec
)
?
sEndSec
:
this
.
parseTimeToSeconds
(
tSegs
.
length
?
tSegs
[
tSegs
.
length
-
1
].
end
:
sEndSec
);
const
tStartOut
=
this
.
serializeTimeByFormat
(
tStartSec
,
tFmt
);
const
tStartOut
=
this
.
serializeTimeByFormat
(
tStartSec
,
tFmt
);
const
tEndOut
=
this
.
serializeTimeByFormat
(
tEndSec
,
tFmt
);
const
tEndOut
=
this
.
serializeTimeByFormat
(
tEndSec
,
tFmt
);
const
zhText
=
(
typeof
m
.
translatedTranslated
===
'
string
'
)
?
m
.
translatedTranslated
:
this
.
buildSentenceFromTranslatedItems
(
tSegs
);
newTList
.
push
({
newTList
.
push
({
start
:
tStartOut
,
start
:
tStartOut
,
end
:
tEndOut
,
end
:
tEndOut
,
translatedItems
:
tSegs
,
translatedItems
:
tSegs
,
translated
:
this
.
buildSentenceFromTranslatedItems
(
tSegs
)
,
translated
:
zhText
,
});
});
}
}
// 用新数组覆盖旧数组(确保下一步导出/覆盖时包含拆分后的完整结果)
// 用新数组覆盖旧数组(确保下一步导出/覆盖时包含拆分后的完整结果)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment