我在东北烤地瓜

I am kaodigua I am chirourou I am qiaodaima

导航

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("别烦我");

ヽ(‘⌒´メ)ノ

(╯' - ')╯︵ ┻━┻

┬─┬ ノ( ' - 'ノ)

━┳━ ━┳━

😔

posted on 2020-11-13 16:45  我在东北烤地瓜  阅读(258)  评论(1编辑  收藏  举报