修复:兼容Chrome公屏语音播放限制
问题:Chrome在页面没有用户操作时拒绝speechSynthesis并返回not-allowed,导致同机Safari有声但Chrome无声。 实现:两个公屏增加一次性声音启用操作,在用户手势中解锁语音;保留每次三遍播报,并补充暂停恢复、失败提示和回归测试。 复现:直接打开公屏页面后由员工端叫号,Chrome不播放声音。
This commit is contained in:
38
web/src/components/SpeechControl.tsx
Normal file
38
web/src/components/SpeechControl.tsx
Normal file
@@ -0,0 +1,38 @@
|
||||
import type { SpeechAnnouncementStatus } from "../hooks/useSpeechAnnouncements";
|
||||
|
||||
interface SpeechControlProps {
|
||||
status: SpeechAnnouncementStatus;
|
||||
onEnable: () => void;
|
||||
}
|
||||
|
||||
export function SpeechControl({ status, onEnable }: SpeechControlProps) {
|
||||
if (status === "ready") {
|
||||
return (
|
||||
<aside className="speech-control speech-control--ready" role="status">
|
||||
<strong>叫号声音已开启</strong>
|
||||
<span>后续叫号将自动播报三次</span>
|
||||
</aside>
|
||||
);
|
||||
}
|
||||
|
||||
const unsupported = status === "unsupported";
|
||||
const failed = status === "error";
|
||||
return (
|
||||
<aside className={`speech-control${failed || unsupported ? " speech-control--error" : ""}`} role="status">
|
||||
<div>
|
||||
<strong>{unsupported ? "当前浏览器不支持叫号声音" : failed ? "叫号声音开启失败" : "叫号声音尚未开启"}</strong>
|
||||
<span>{unsupported || failed ? "请确认系统已安装中文语音服务" : "Chrome 需要先点击一次,之后才允许自动播报"}</span>
|
||||
</div>
|
||||
{!unsupported ? (
|
||||
<button
|
||||
className="button button--primary"
|
||||
type="button"
|
||||
disabled={status === "enabling"}
|
||||
onClick={onEnable}
|
||||
>
|
||||
{status === "enabling" ? "正在开启叫号声音" : failed ? "重新开启叫号声音" : "开启叫号声音"}
|
||||
</button>
|
||||
) : null}
|
||||
</aside>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user