美文网首页
js实现文字转语音

js实现文字转语音

作者: 曲昶光 | 来源:发表于2021-11-11 16:20 被阅读0次

    SpeechSynthesisUtterance()函数

    函数目前处于实验性阶段,在使用它之前,请仔细检查浏览器兼容性表。

    text – 要合成的文字内容,字符串
    lang – 使用的语言,字符串, 例如:“zh-cn”
    voiceURI – 指定希望使用的声音和服务,字符串
    volume – 声音的音量,区间范围是0到1,默认是1
    rate – 语速,数值,默认值是1,范围是0.1到10,表示语速的倍数,例如2表示正常语速的两倍。
    pitch – 表示说话的音高,数值,范围从0(最小)到2(最大)。默认值为1

    speechSynthesis属性

    SpeechSynthesis.paused 只读
    SpeechSynthesis 处于暂停状态时, Boolean 值返回 true

    SpeechSynthesis.pending 只读
    当语音播放队列到目前为止保持没有说完的语音时, Boolean 值返回 true

    SpeechSynthesis.speaking 只读
    当语音谈话正在进行的时候,即使SpeechSynthesis处于暂停状态, Boolean 返回 true

    具体使用

    function speak() {
        var utterThis = new window.SpeechSynthesisUtterance()
        utterThis.text = "测试测试测试测试";
     window.speechSynthesis.speak(utterThis)
      }
      speak();
    

    相关文章

      网友评论

          本文标题:js实现文字转语音

          本文链接:https://www.haomeiwen.com/subject/jhhgzltx.html