forked from mrlan/EnglishPal
				
			Use better variable names.
							parent
							
								
									b0f1e707b1
								
							
						
					
					
						commit
						13b39cf85c
					
				|  | @ -1,8 +1,8 @@ | ||||||
| let isRead = true; | let isRead = true; | ||||||
| let isChoose = true; | let isChoose = true; | ||||||
| let reader = window.speechSynthesis; // 全局定义朗读者,以便朗读和暂停
 | let reader = window.speechSynthesis; // 全局定义朗读者,以便朗读和暂停
 | ||||||
| let cur_position = 0; // 朗读文本的当前位置
 | let current_position = 0; // 朗读文本的当前位置
 | ||||||
| let orig_position = 0; // 朗读文本的初始位置
 | let original_position = 0; // 朗读文本的初始位置
 | ||||||
| let to_speak = ""; // 朗读的初始内容
 | let to_speak = ""; // 朗读的初始内容
 | ||||||
| 
 | 
 | ||||||
| function getWord() { | function getWord() { | ||||||
|  | @ -25,7 +25,7 @@ function makeUtterance(str, rate) { | ||||||
|     msg.lang = "en-US"; // TODO: add language options menu
 |     msg.lang = "en-US"; // TODO: add language options menu
 | ||||||
|     msg.onboundary = ev => { |     msg.onboundary = ev => { | ||||||
|         if (ev.name == "word") { |         if (ev.name == "word") { | ||||||
|             cur_position = ev.charIndex; |             current_position = ev.charIndex; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|     return msg; |     return msg; | ||||||
|  | @ -38,16 +38,16 @@ inputSlider.oninput = () => { | ||||||
|     sliderValue.textContent = value + '×'; |     sliderValue.textContent = value + '×'; | ||||||
|     if (!reader.speaking) return; |     if (!reader.speaking) return; | ||||||
|     reader.cancel(); |     reader.cancel(); | ||||||
|     let msg = makeUtterance(to_speak.substring(orig_position + cur_position), value); |     let msg = makeUtterance(to_speak.substring(original_position + current_position), value); | ||||||
|     orig_position = orig_position + cur_position; |     original_position = original_position + current_position; | ||||||
|     cur_position = 0; |     current_position = 0; | ||||||
|     reader.speak(msg); |     reader.speak(msg); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| function read(s) { | function read(s) { | ||||||
|     to_speak = s.toString(); |     to_speak = s.toString(); | ||||||
|     orig_position = 0; |     original_position = 0; | ||||||
|     cur_position = 0; |     current_position = 0; | ||||||
|     let msg = makeUtterance(to_speak, inputSlider.value); |     let msg = makeUtterance(to_speak, inputSlider.value); | ||||||
|     reader.speak(msg); |     reader.speak(msg); | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue