• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

VUE 文字转语音播放的实现展示亲测好用

武飞扬头像
zxna
帮助2

三、vue项目案例

<template>
     <button @click="playVoice">播放语音</button>
</template>
<script>
const synth = window.speechSynthesis;
const msg = new SpeechSynthesisUtterance();
export default {
     data() {
     return {};
     },
     methods: {
     playVoice() {
     this.handleSpeak('小朋友,你是否有很多问号') // 传入需要播放的文字
     },
     // 语音播报的函数
     handleSpeak(text) {
     msg.text = text; // 文字内容: 小朋友,你是否有很多问号
     msg.lang = "zh-CN"; // 使用的语言:中文
     msg.volume = 1; // 声音音量:1
     msg.rate = 1; // 语速:1
     msg.pitch = 1; // 音高:1
     synth.speak(msg); // 播放
     },
     // 语音停止
     handleStop(e) {
     msg.text = e;
     msg.lang = "zh-CN";
     synth.cancel(msg);
     }
     }
};
</script>
学新通

一、技术:Web Speech API
Web Speech API 使您能够将语音数据合并到 Web 应用程序中。

Web Speech API 有两个部分:SpeechSynthesis 语音合成 (文本到语音 TTS)和 SpeechRecognition 语音识别(异步语音识别)。

二、语音合成及发音接口
SpeechSynthesis:语音合成服务的控制器接口,可用于获取设备上可用的合成语音,开始、暂停以及其它相关命令的信息。

SpeechSynthesisUtterance:表示一次发音请求。其中包含了将由语音服务朗读的内容,以及如何朗读它(例如:语种、音高、音量)。

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhfijicj
系列文章
更多 icon
同类精品
更多 icon
继续加载