gpt4 book ai didi

javascript - ResponsiveVoice.js - 绕过 iOS TTS 需要直接用户交互

转载 作者:可可西里 更新时间:2023-11-01 04:40:56 26 4
gpt4 key购买 nike

关于 ResponsiveVoice.JS website在怪癖部分下,它指出:

iOS TTS can’t be triggered without a direct user interaction, ResponsiveVoice JS resolves this

但是,对于我来说,我无法绕过这种直接的用户交互需求。 你如何解决这个问题?

这是我尝试在没有用户交互的情况下执行的代码片段,我目前位于 <head> 中元素:

<script src="http://code.responsivevoice.org/responsivevoice.js"></script>
<script type="text/javascript">
function speak_static_data(){
responsiveVoice.speak('Test');
}
setTimeout(function(){ speak_static_data(); }, 3000);
</script>

我想调用responsiveVoice.speak('Test');在没有直接用户交互的情况下在 iOS 中加载页面。我该怎么做?

同样的代码片段在 Android/桌面版 Safari/桌面版 Chrome 上运行良好,但在 iOS 上却不行。

最佳答案

所以我四处搜索并隐藏在他们的常见问题解答中,他们有 iOS 指南。他们并没有完全规避它,而是在第一次出现后就一直绕过它。

On iOS, some events such as Speech Synthesis, need to be triggered from a user action (i.e. a click). That causes ResponsiveVoice speak calls not to work on page load, for example.

With Speech Synthesis, that user triggered action only needs to be done once. Further direct calls after the first one will work as expected.

So, the recommended best practice is to add a “Start” button to the experience for the user to click, and use that as a initialization call to responsiveVoice.speak(). That call, if desired, can have a blank space as text, so there’s no impact to the user.

您实际上不需要说任何话,因此拥有一个用户只需单击调用响应式语音的按钮就足够了。

<button onclick="responsiveVoice.speak('');">Enable Voice</button>

响应语音常见问题解答:https://responsivevoice.org/faq/

关于javascript - ResponsiveVoice.js - 绕过 iOS TTS 需要直接用户交互,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41625937/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com