当前位置:网站首页>JS convert text to language for playback
JS convert text to language for playback
2022-06-13 06:08:00 【HaanLen】
SpeechSynthesisUtterance Basic attributes
SpeechSynthesisUtterance.lang // Acquire and set the language of the discourse
SpeechSynthesisUtterance.pitch // Get and set the tone of the words ( The higher the value, the sharper , The lower, the lower )
SpeechSynthesisUtterance.rate // Get and set the speaking speed ( The higher the value, the faster the speech , The less you talk, the slower you talk )
SpeechSynthesisUtterance.text // Get and set the text when speaking
SpeechSynthesisUtterance.voice // Get and set the voice to speak
SpeechSynthesisUtterance.volume // Gets and sets the volume of speech
SpeechSynthesisUtterance The basic method
boundary or onboundary// When the utterance reaches the boundary of a word or sentence .
end or onend // Triggered when the utterance is finished .
error or onerror// Triggered when an error occurs that makes it impossible to speak successfully .
mark or onmark // When the voice reaches a named SSML“ Mark ” Trigger when labeling .
pause or onpause // Triggered when a pause occurs .
resume or onresume// Triggered when the paused utterance resumes .
start or onstart // Triggered when words begin to be spoken .
speechSynthesis object , The main function is to trigger behavior , For example, read , stop , Reduction, etc
window.speechSynthesis.speak(msg)
speak() //– receive calls only SpeechSynthesisUtterance As a unique parameter , The function is to read synthetic discourse .
cancel() //– Delete all voice in the queue . If it's playing , Then stop .
pause() //– Pause the synthesis process .
resume() //– Restart the synthesis process .
getVoices //– This method does not accept any parameters , Used to return the list of voice packets supported by the browser. Note : Must be added to voiceschanged Only in the event can it take effect , Is an array
Example
<body>
<button id="btn"> Click on </button>
</body>
<script type="text/javascript">
let dom = document.getElementById('btn');
dom.addEventListener('click', function(e) {
console.log('mmm');
let msg = new SpeechSynthesisUtterance();
msg.text = ` Poetry learning : Cage osprey , In the river of continent . My fair lady , The gentleman good qiu . Jagged nymphoides , The flow around . My fair lady , The May 5 . exceedingly welcome , I can't sleep without thinking . free from restraint , toss and turn restlessly . Jagged nymphoides , Take it from the left and right . My fair lady , Friends of zither and zither . Jagged nymphoides , It's about the left and right . My fair lady , Bell and drum music .`;
msg.lang = "zh-CN"; // The language used : chinese
msg.volume = 2; // Sound volume :1
msg.rate = 1; // The speed :1
msg.pitch = 1; // pitch :1
window.speechSynthesis.speak(msg)
})
</script>
边栏推荐
- Adding classes dynamically in uni app
- Local file search tool everything
- USB debugging assistant
- 微信小程序:点击事件获取当前设备信息(基础)
- 高迸发解决方案2
- Minimum spanning tree (prim+kruskal) learning notes (template +oj topic)
- Audio stereo to mono (Audio Dual Channel to mono channel)
- Leetcode- student attendance record i- simple
- Concurrent programming -- source code analysis of thread pool
- USB debugging assistant (20191028)
猜你喜欢
随机推荐
Leetcode- first unique character in string - simple
【DP之01背包】
Shardingsphere JDBC exception: no table route info
微信小程序:基础复习
高迸发解决方案2
js-bom
How MySQL optimizes the use of joint index ABC
Leetcode Hamming distance simple
自定义View —— 可伸展的CollapsExpendView
USB status error and its cause (error code)
Printf function
Leetcode- key formatting - simple
Tongweb crawl performance log script
MySQL stored procedure
The Boys x PUBGMOBILE 联动火热来袭!来看最新游戏海报
Record the basic use of zxing, the Google open source library, to generate and read QR codes
Tongweb card, tongweb card, tongweb card
Missing tag identification in cots RFID systems: bringing the gap between theory and Practice
Status management --provider
Swift--function