feat: pre translate time

This commit is contained in:
Gabe
2025-11-10 01:08:09 +08:00
parent 4b3853dd22
commit 222428ad47
4 changed files with 45 additions and 4 deletions

View File

@@ -1864,6 +1864,16 @@ export const I18N = {
en: `Style Code`,
zh_TW: `樣式程式碼`,
},
pre_trans_seconds: {
zh: `提前翻译时长 (10-36000s)`,
en: `Pre translation seconds (10-36000s)`,
zh_TW: `提前翻译时长 (10-36000s)`,
},
throttle_trans_interval: {
zh: `节流翻译间隔 (1-3600s)`,
en: `Throttling translation interval (1-3600s)`,
zh_TW: `节流翻译间隔 (1-3600s)`,
},
};
export const newI18n = (lang) => (key) => I18N[key]?.[lang] || "";

View File

@@ -112,6 +112,8 @@ export const DEFAULT_SUBTITLE_SETTING = {
apiSlug: OPT_TRANS_MICROSOFT,
segSlug: "-", // AI智能断句
chunkLength: 1000, // AI处理切割长度
preTrans: 90, // 提前翻译时长
throttleTrans: 30, // 节流翻译间隔
// fromLang: "en",
toLang: "zh-CN",
isBilingual: true, // 是否双语显示

View File

@@ -12,8 +12,8 @@ export class BilingualSubtitleManager {
#captionWindowEl = null;
#paperEl = null;
#currentSubtitleIndex = -1;
#preTranslateSeconds = 90;
#throttleSeconds = 30;
// #preTranslateSeconds = 90;
// #throttleSeconds = 30;
#setting = {};
#isAdPlaying = false;
#throttledTriggerTranslations;
@@ -34,7 +34,7 @@ export class BilingualSubtitleManager {
this.#throttledTriggerTranslations = throttle(
this.#triggerTranslations.bind(this),
this.#throttleSeconds * 1000
(setting.throttleTrans ?? 30) * 1000
);
}
@@ -294,7 +294,8 @@ export class BilingualSubtitleManager {
* @param {number} currentTimeMs
*/
#triggerTranslations(currentTimeMs) {
const lookAheadMs = this.#preTranslateSeconds * 1000;
const { preTrans = 90 } = this.#setting;
const lookAheadMs = preTrans * 1000;
for (const sub of this.#formattedSubtitles) {
const isCurrent = sub.start <= currentTimeMs && sub.end >= currentTimeMs;

View File

@@ -30,6 +30,8 @@ export default function SubtitleSetting() {
apiSlug,
segSlug,
chunkLength,
preTrans = 90,
throttleTrans = 30,
toLang,
isBilingual,
skipAd = false,
@@ -114,6 +116,32 @@ export default function SubtitleSetting() {
max={20000}
/>
</Grid>
<Grid item xs={12} sm={12} md={6} lg={3}>
<ValidationInput
fullWidth
size="small"
label={i18n("pre_trans_seconds")}
type="number"
name="preTrans"
value={preTrans}
onChange={handleChange}
min={10}
max={36000}
/>
</Grid>
<Grid item xs={12} sm={12} md={6} lg={3}>
<ValidationInput
fullWidth
size="small"
label={i18n("throttle_trans_interval")}
type="number"
name="throttleTrans"
value={throttleTrans}
onChange={handleChange}
min={1}
max={3600}
/>
</Grid>
<Grid item xs={12} sm={12} md={6} lg={3}>
<TextField
fullWidth