Skip to content

effycoco/text-to-speech

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Text to Speech 文字转语音

A project from JavaScript 30 -23

What I learned

  1. 文字转语音的简化步骤
    const msg = new SpeechSynthesisUtterance();
    msg.text = "hello";
    speechSynthesis.speak(msg);
  2. 更改语言
    // 接上
    let voices;
    voices = speechSynthesis.getVoices();
    // 如果直接写let voices=speechSynthesis.getVoices()会得到空数组,为什么?
    msg.text = "您好";
    msg.voice = voices.find((voice) => voice.lang === "zh-CN");
    speechSynthesis.speak(msg);
  3. 设置msg.rate, msg.pitch可更改语音的速度和音高
  4. array.find()只返回第一个符合条件的元素
  5. 向回调函数传递参数可以使用bind, egele.addEventListener('click',toggle.bind(null,false)) is the same as ele.addEventListener('click',()=>toggle(false)) and ele.addEventListener('click',function(){toggle(false)}
  6. global variable 既可以直接在 js 中使用,也可以在前面加上window., 如 window.speechSythesis or just speechSythesis

Reference

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published