2 Commits
Author SHA1 Message Date
kicer 03cf4b86e4 语音松手后的识别提示改为动态进度:段数 + 秒数
「正在识别…」是静态文案,上游慢时看着像卡死。改成按真实进度变化:

- 多段:正在识别 2/3 段 · 5s(每完成一段分子加一)
- 单段:正在识别… 5s(0/1 看着也像没进展,只留秒数)
- 秒数 1s 一跳,从松手(尾巴已入队)才开始算,说话过程不计时
- 失败也算走完一段,进度不会停在半路
- resetUI 统一 clearInterval:取消/超时/完成/切模式都不会漏
2026-11-11 08:55:40 +08:00
kicer 7641f5c0a7 鸿蒙长按时按住区不再随遮罩隐藏:避免指针捕获被释放而误判“说话太短”
按下后 body.voice-active 会把输入卡所有子项设成 visibility:hidden,#voice-hold 也在内。
它是 pointerdown 里 setPointerCapture 的持有者,鸿蒙 ArkWeb 在元素不可见时会释放捕获并
补一个 pointercancel,页面把它当成“松手”→ 按住不到 500ms → 丢弃并提示“说话时间太短”,
表现就是长按立刻失效、按钮像丢了状态。

- 只把 #voice-hold 排除在隐藏规则外(遮罩覆盖这一段本来就不透明,视觉无差别)
- 其余元素(输入框、操作栏等)的隐藏行为保持不变
- 未改 JS:录音状态机、取消手势阈值、识别流程都不动

真机确认有效后再看是否需要处理 setPointerCapture 与长按序列打断。
2026-11-11 08:48:14 +08:00
2 changed files with 49 additions and 4 deletions
+5 -1
View File
@@ -440,7 +440,11 @@ footer { position: relative; flex: none; padding: 8px 12px calc(10px + var(--sab
/* 录音期间:输入卡内容整体让位给遮罩(遮罩不再透光,按钮/文字留着会和提示叠字) */ /* 录音期间:输入卡内容整体让位给遮罩(遮罩不再透光,按钮/文字留着会和提示叠字) */
body.voice-active .input-shell { border-color: transparent; box-shadow: none; } body.voice-active .input-shell { border-color: transparent; box-shadow: none; }
body.voice-active .input-shell > *:not(#voice-overlay) { visibility: hidden; } /* #voice-hold 不能一起藏:它是 pointerdown 时 setPointerCapture 的持有者,一按下就变成
visibility:hidden 时鸿蒙 ArkWeb 会释放捕获并补一个 pointercancel,页面把它当成“松手”
→ 按住不到 500ms → 误报“说话时间太短”。遮罩覆盖这一段本来就不透明(var(--page)),
留着按住区视觉上没有差别。 */
body.voice-active .input-shell > *:not(#voice-overlay):not(#voice-hold) { visibility: hidden; }
body.voice-active .attach-chips { visibility: hidden; } body.voice-active .attach-chips { visibility: hidden; }
body.voice-active .scroll-bottom-btn { display: none; } body.voice-active .scroll-bottom-btn { display: none; }
+44 -3
View File
@@ -76,6 +76,10 @@
let segLen = 0; // 当前段总采样数 let segLen = 0; // 当前段总采样数
let silLen = 0; // 段尾连续静音采样数 let silLen = 0; // 段尾连续静音采样数
let textParts = []; // 各段识别结果(按顺序) let textParts = []; // 各段识别结果(按顺序)
let segSent = 0; // 本轮已提交转写的段数(进度分母)
let segDone = 0; // 已返回(含失败)的段数(进度分子)
let busyTimer = null; // 「识别中」提示的秒表(1s 一跳)
let busyStartAt = 0;
let chain = Promise.resolve(); // 串行上传链:保证拼接顺序 = 说话顺序 let chain = Promise.resolve(); // 串行上传链:保证拼接顺序 = 说话顺序
let gen = 0; // 会话代号:取消/重录后迟到结果直接丢弃 let gen = 0; // 会话代号:取消/重录后迟到结果直接丢弃
let streamOn = false; // 是否接受 PCM 分片 let streamOn = false; // 是否接受 PCM 分片
@@ -115,10 +119,35 @@
if (overlay) overlay.classList.toggle('cancel', m === 'cancel'); if (overlay) overlay.classList.toggle('cancel', m === 'cancel');
if (hintEl) { if (hintEl) {
hintEl.textContent = m === 'cancel' ? '松开取消' hintEl.textContent = m === 'cancel' ? '松开取消'
: m === 'busy' ? '正在识别…' : '松手传送,上滑取消'; : m === 'busy' ? busyHintText() : '松手传送,上滑取消';
} }
} }
// 「识别中」的进度提示:段数是真实进度(一段一次转写),秒数让长时间等待时数字也在动,
// 不至于看着像卡住。只有一段时不显示 0/1(那看着也像没进展),只留秒数。
function busyHintText() {
const sec = Math.max(0, Math.floor((Date.now() - busyStartAt) / 1000));
if (segSent > 1) {
return '正在识别 ' + Math.min(segDone, segSent) + '/' + segSent + ' 段 · ' + sec + 's';
}
return '正在识别… ' + sec + 's';
}
function refreshBusyHint() {
if (hintEl && phase === 'busy') hintEl.textContent = busyHintText();
}
function stopBusyTicker() {
if (busyTimer) { clearInterval(busyTimer); busyTimer = null; }
}
function startBusyTicker() {
stopBusyTicker();
busyStartAt = Date.now();
refreshBusyHint();
busyTimer = setInterval(refreshBusyHint, 1000);
}
function renderBars(level, animate) { function renderBars(level, animate) {
if (!bars.length) return; if (!bars.length) return;
const t = Date.now() / 1000; const t = Date.now() / 1000;
@@ -260,6 +289,7 @@
pressing = false; pressing = false;
pressY = 0; pressY = 0;
discard = false; discard = false;
stopBusyTicker();
abortStream(); abortStream();
if (stopTimer) { clearTimeout(stopTimer); stopTimer = null; } if (stopTimer) { clearTimeout(stopTimer); stopTimer = null; }
hold.classList.remove('recording'); hold.classList.remove('recording');
@@ -302,6 +332,8 @@
if (phase !== 'idle') return; if (phase !== 'idle') return;
pressing = true; pressing = true;
discard = false; discard = false;
segSent = 0;
segDone = 0;
hold.classList.add('recording'); hold.classList.add('recording');
setHoldText('松开 结束'); setHoldText('松开 结束');
showOverlay(); showOverlay();
@@ -371,7 +403,7 @@
phase = 'busy'; phase = 'busy';
hold.classList.remove('recording'); hold.classList.remove('recording');
setHoldText(discard ? '按住 说话' : '正在识别…'); setHoldText(discard ? '按住 说话' : '正在识别…');
// 遮罩留着,文案换成「正在识别…」;柱子停在低位,等结果回来再收 // 遮罩留着,文案换成动态识别进度;柱子停在低位,等结果回来再收
setOverlayMode(discard ? 'send' : 'busy'); setOverlayMode(discard ? 'send' : 'busy');
stopMeter(); stopMeter();
@@ -387,6 +419,7 @@
// 两条路收口完全一样:把不足一个停顿的尾巴发走(纯静音的尾巴不发),再等所有段回来。 // 两条路收口完全一样:把不足一个停顿的尾巴发走(纯静音的尾巴不发),再等所有段回来。
// 大部分段在说话过程中已经识别完了,这里通常只等最后一段。 // 大部分段在说话过程中已经识别完了,这里通常只等最后一段。
flushTail(); flushTail();
startBusyTicker(); // 尾巴已进队列:现在才有准确的总段数,从这一刻开始计时
if (native) { if (native) {
try { try {
native.stopVoice(); native.stopVoice();
@@ -547,15 +580,23 @@
// 串行上传:一段没回来不发下一段(2 vCPU 上并发只会互相拖慢,而且顺序也没法保证) // 串行上传:一段没回来不发下一段(2 vCPU 上并发只会互相拖慢,而且顺序也没法保证)
function emit(blob) { function emit(blob) {
const my = gen; const my = gen;
segSent++; // 分母:已提交的段数(含排队中的)
chain = chain.then(function () { chain = chain.then(function () {
if (my !== gen) return; // 已取消/重录:不再发 if (my !== gen) return; // 已取消/重录:不再发
return req('POST', '/api/asr/transcribe', blob, true, 120000) return req('POST', '/api/asr/transcribe', blob, true, 120000)
.then(function (r) { .then(function (r) {
if (my !== gen) return; if (my !== gen) return;
segDone++;
const t = String((r && r.text) || '').replace(/\s+/g, ' ').trim(); const t = String((r && r.text) || '').replace(/\s+/g, ' ').trim();
if (t) textParts.push(t); if (t) textParts.push(t);
refreshBusyHint();
}) })
.catch(function () { /* 单段失败不连坐,其余段照常出字 */ }); .catch(function () {
/* 单段失败不连坐,其余段照常出字;失败也算走完一段,进度才不会停在半路 */
if (my !== gen) return;
segDone++;
refreshBusyHint();
});
}); });
} }