在线语音合成工具代码

╰半橙微兮° 2024-03-22 13:25 110阅读 0赞

95a2d720a94f4e499418c88dc621eb72.png

  • 语音合成软件
  • 语音合成助手免费版下载
  • 语音合成助手
  • 语音合成技术
  • 语音合成
  • 语音合成工具下载
  • 语音合成软件哪个好用
  • 语音合成软件免费版
  • 语音合成网易有道智云
  • 语音合成网站




































    1. <script>
    2. new Vue({
    3. el: "#app",
    4. data: {
    5. set: {
    6. input: "山有木兮木有枝,心悦君兮君不知。",
    7. rate: 1,
    8. pitch: 1,
    9. voice: 1,
    10. voices: []
    11. },
    12. synth: null
    13. },
    14. created() {
    15. if (window.speechSynthesis === undefined) {
    16. $message.error("该浏览器不支持语音生成,请更换Chrome浏览器后重试");
    17. return;
    18. }
    19. this.synth = window.speechSynthesis;
    20. window.speechSynthesis.onvoiceschanged = e => {
    21. this.set.voices = window.speechSynthesis.getVoices();
    22. this.set.voice = this.set.voices[0].name;
    23. };
    24. },
    25. methods: {
    26. play() {
    27. try {
    28. const utterThis = new SpeechSynthesisUtterance(this.set.input);
    29. this.set.voices.forEach(value => {
    30. if (this.set.voice === value.name) {
    31. utterThis.voice = value;
    32. }
    33. });
    34. utterThis.pitch = this.set.pitch;
    35. utterThis.rate = this.set.rate;
    36. this.synth.cancel();
    37. this.synth.speak(utterThis);
    38. } catch (e) {
    39. $message.error(e);
    40. }
    41. },
    42. reset() {
    43. this.set.input = "";
    44. }
    45. }
    46. });
    47. </script>

发表评论

表情:
评论列表 (有 0 条评论,110人围观)

还没有评论,来说两句吧...

相关阅读