当前位置:网站首页>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>

 Insert picture description here

原网站

版权声明
本文为[HaanLen]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/164/202206130603576201.html