美文网首页
JS文字转语音TTS

JS文字转语音TTS

作者: 林万程 | 来源:发表于2021-01-10 02:16 被阅读0次

周末写的一个Vue网页智力游戏埋了发音彩蛋,分享下发音代码
http://linwancen.gitee.io/vantgames
百度不支持日文片假名,要是有支持日文片假名的免费引擎欢迎推荐
src/util/speak.js

/**
 * 百度语音合成 TTS(Text To Speech)
 */
export function speak(s) {
  new Audio(
      'http://tts.baidu.com/text2audio' +
      '?lan=zh' +
      '&ie=UTF-8' +
      '&spd=9' +
      '&text=' + s
  ).play().catch(e => {
    console.log('speak:"' + s + '" error:' + e)
  })
}

使用

import {speak} from "@/util/speak"
speak(s)

相关文章

网友评论

      本文标题:JS文字转语音TTS

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