dudududadada

vue 在线文字转语音

在线文字转语音

说不上来有点傻气的功能

首先要用到百度翻译语音那个接口http://tts.baidu.com/text2audio

参数lan语言,lan:语言,ie:编码,spd:语速(1-9),text:要朗读的内容

有没有男声女声12的我忘了

....我好像写过这篇啊

这个要用到audio标签 ,大概就是长这样

<audio autoplay >
	<source src="http://tts.baidu.com/text2audio?lan=zh&ie=UTF-8&spd=4&text=我好暴躁" type="audio/mpeg">
	<embed height="0" width="0" src="http://tts.baidu.com/text2audio?text=我好暴躁">
</audio>

差不多就这些东西,完事写一个方法,写main.js里

Vue.prototype.audioPlay=function(text){
  var zhText = text;
  zhText = encodeURI(zhText);
  var audio =
    \'<audio autoplay="autoplay">\' +
    \'<source src="http://tts.baidu.com/text2audio?lan=zh&ie=UTF-8&spd=4&text=\' +
    zhText +
    \'" type="audio/mpeg">\' +
    \'<embed height="0" width="0" src="http://tts.baidu.com/text2audio?text=\' +
    zhText +
    \'">\' +
    "</audio>";
  $("body").append(audio);
 
}


//用的时候
this.audioPlay("别烦我");

ヽ(‘⌒´メ)ノ

(╯\' - \')╯︵ ┻━┻

┬─┬ ノ( \' - \'ノ)

━┳━ ━┳━

分类:

技术点:

相关文章:

  • 2021-11-29
  • 2022-01-02
  • 2021-07-14
  • 2022-12-23
  • 2022-01-09
  • 2021-12-23
  • 2021-10-16
  • 2021-09-12
猜你喜欢
  • 2021-11-17
  • 2022-01-07
  • 2022-12-23
  • 2021-11-23
  • 2021-12-13
  • 2022-12-23
相关资源
相似解决方案