语音综合在Safari Macos中不起作用12.3

发布于 2025-01-28 08:26:19 字数 1733 浏览 3 评论 0原文

语音综合API在MacOS 12.3上无法使用Safari(它在MACOS11上起作用)。我有以下代码,当用户单击一个按钮时,请调用speaknow()函数。在功能中,将创建新的语音语言和窗口。SpeeChsynthesis.speak(Tusterance)将被调用。之后,期望tublesance.onstart(),发声的声音,然后称呼tustance.onend()。

function speaknow() {
    if ('speechSynthesis' in window)  {
        window.utterances = [];
        this.utterance = new SpeechSynthesisUtterance();
        this.utterance.text = 'Speaker on';
        window.utterances.push(this.utterance);
                  
        this.utterance.onstart = function(event) {
            console.info('this.utterance.onstart()');
        }
        this.utterance.onend = function(){
            console.info('this.utterance.onend()');
        };
        this.utterance.onerror = function(event) {
            console.error('error utterance ', event );
        }
           
        window.speechSynthesis.speak(this.utterance);
        setTimeout(function(){
            // NOTE: forceStop=true is set through button click
            if (!window.speechSynthesis.speaking && (!forceStop)) {
                speaknow(); // re-attempt
                console.info('window.speechSynthesis is not speaking. Re-attempt speaknow().');
            }
            else if (window.speechSynthesis.speaking) {
                console.info('window.speechSynthesis.speaking: ' + window.speechSynthesis.speaking);
            }
        },500);
    }
}

观察:

  1. 根本没有声音。
  2. 在第一次time window.speechsynthesis.speak()被调用,tusterance.onstart()从未被调用,但是tusterance.onend()被调用。
  3. window.speechsynthesis.speaking始终是正确的。
  4. 对于下一个time window.speechsynthesis.speak()被调用,tublesance.onstart()和tusterance.onend()均被调用。 window.speechsynthesis。说话仍然是真实的,但仍然没有声音。

The Speech Synthesis API does not work on Safari on MacOS 12.3 (It is working on MacOS11). I have the code below where when user clicks a button will call speaknow() function. In the function, new SpeechUtterance utterance is created and window.speechSynthesis.speak(utterance) will be called. Afterwards, it is expected for utterance.onstart(), sound of the utterance, then utterance.onend() to be called.

function speaknow() {
    if ('speechSynthesis' in window)  {
        window.utterances = [];
        this.utterance = new SpeechSynthesisUtterance();
        this.utterance.text = 'Speaker on';
        window.utterances.push(this.utterance);
                  
        this.utterance.onstart = function(event) {
            console.info('this.utterance.onstart()');
        }
        this.utterance.onend = function(){
            console.info('this.utterance.onend()');
        };
        this.utterance.onerror = function(event) {
            console.error('error utterance ', event );
        }
           
        window.speechSynthesis.speak(this.utterance);
        setTimeout(function(){
            // NOTE: forceStop=true is set through button click
            if (!window.speechSynthesis.speaking && (!forceStop)) {
                speaknow(); // re-attempt
                console.info('window.speechSynthesis is not speaking. Re-attempt speaknow().');
            }
            else if (window.speechSynthesis.speaking) {
                console.info('window.speechSynthesis.speaking: ' + window.speechSynthesis.speaking);
            }
        },500);
    }
}

Observation:

  1. No sound at all.
  2. During the first time window.speechSynthesis.speak() gets called, utterance.onstart() never gets called, but utterance.onend() gets called.
  3. window.speechSynthesis.speaking is always true.
  4. For the next time window.speechSynthesis.speak() gets called, neither utterance.onstart() nor utterance.onend() gets called. window.speechSynthesis.speaking remains true but still no sound.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文