Vue implements text-to-speech method: 1. Create a SpeechSynthesisUtterance object; 2. Implement browser judgment through "isIe(){...}" method; 3. According to the ie usage method, the code Such as "if(this.isIe()){let voiceObj = new ActiveXObject("Sapi.SpVoice")voiceObj.Rate = ...)".
The operating environment of this tutorial: windows7 system, vue3, Dell G3 computer.
How does vue implement text-to-speech?
Detailed explanation of the text-to-speech function in vue
Currently, h5 has added a new text-to-speech function (but it is being improved and is barely usable), h5's new SpeechSynthesisUtterance instance
First create a new SpeechSynthesisUtterance object
Use some attributes of the instance object, including:
text – the text content to be synthesized, a string.
lang – the language used, string, for example: "zh-cn"
voiceURI – specifies the voice and service you want to use, String.
volume – The volume of the sound, ranging from 0 to 1, the default is 1.
rate – speaking rate, numerical value, the default value is 1, the range is 0.1 to 10, indicating a multiple of the speaking speed, for example, 2 represents twice the normal speaking speed.
pitch – Indicates the pitch of speech, numerical value, ranging from 0 (minimum) to 2 (maximum). The default value is 1.
Method
speak() Add the corresponding instance to the voice queue
cancel() Delete all the voices in the queue. If it is playing, stop it directly
pause() Pause the voice
resume() Resumes the paused voice
getVoices Gets the supported language array. Note: It must be added to the voiceschanged event to take effect
But This method does not support the old version of IE. You need to add the browser judgment method
isIe(){ if(!!window.ActiveXObject || "ActiveXObject " in window){ return true }else{ return false } },
and then follow the IE usage method
voice(e){ window.speechSynthesis.cancel() let timer timer = setInterval(() => { let msg = e if(this.isIe()){ let voiceObj = new ActiveXObject("Sapi.SpVoice") voiceObj.Rate = -1 // 语速 voiceObj.Volume = 50 // 音量 voiceObj.Speak(msg,1) }else{ let speakMsg = new SpeechSynthesisUtterance(msg) speakMsg.rate = 1 // 语速 speakMsg.pitch = 3 // 音量 window.speechSynthesis.speak(speakMsg) } }, 1000) setTimeout(() => { // 一段时间后清除定时器 clearInterval(timer) }, 1000) },
. Recommended learning: "vue.js video tutorial"
The above is the detailed content of How to implement text-to-speech in vue. For more information, please follow other related articles on the PHP Chinese website!

vue中props可以传递函数;vue中可以将字符串、数组、数字和对象作为props传递,props主要用于组件的传值,目的为了接收外面传过来的数据,语法为“export default {methods: {myFunction() {// ...}}};”。

本篇文章带大家聊聊vue指令中的修饰符,对比一下vue中的指令修饰符和dom事件中的event对象,介绍一下常用的事件修饰符,希望对大家有所帮助!

如何覆盖组件库样式?下面本篇文章给大家介绍一下React和Vue项目中优雅地覆盖组件库样式的方法,希望对大家有所帮助!

react与vue的虚拟dom没有区别;react和vue的虚拟dom都是用js对象来模拟真实DOM,用虚拟DOM的diff来最小化更新真实DOM,可以减小不必要的性能损耗,按颗粒度分为不同的类型比较同层级dom节点,进行增、删、移的操作。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
