Last active
June 15, 2017 09:35
-
-
Save maicong/936950c3e1f7a2e7beaac55cea56e6a4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 使用百度语音合成自动文本转语音 | |
| * | |
| * 进入 http://ai.baidu.com/tech/speech/tts ,打开 console,粘贴本代码 | |
| */ | |
| // 生成文本列表:通过直接定义 | |
| const text = '当不幸降临在他人头上时,他们往往都能像智者一样劝慰别人;而当同样的不幸降临自己身上时,人往往很难同样地开导自己。人最大的不智不是不知道,而是知道了却迟迟不愿去做,所以平庸却又自怜的人很多。' | |
| const textArr = text | |
| .replace(/(;|。|\n|\r)/g, '__line__') | |
| .split('__line__') | |
| .filter(v => { | |
| return /[A-Za-z0-9\u3000\u3400-\u4DBF\u4E00-\u9FFF]+/i.test(v) | |
| }) | |
| // 生成文本列表:通过抓取页面内容 | |
| // (进入任意网页,打开控制台,在 Elements 中选中内容所在的 element,切换到 console,输入:) | |
| // const textArr = JSON.stringify( | |
| // $0.innerText | |
| // .replace(/(;|。|\n|\r)/g, '__line__') | |
| // .split('__line__') | |
| // .filter(v => { | |
| // return /[A-Za-z0-9\u3000\u3400-\u4DBF\u4E00-\u9FFF]+/i.test(v) | |
| // }) | |
| // ) | |
| /** | |
| * 播放语音 | |
| * | |
| * console,输入: | |
| */ | |
| ;(i => { | |
| const $ = ele => { | |
| return document.querySelector(ele) || null | |
| } | |
| const timer = setInterval(() => { | |
| const play = $('.player.play') | |
| if (play && textArr[i]) { | |
| $('#demo-text-content').value = textArr[i] | |
| $('[data-per="4"]').click() | |
| play.click() | |
| i++ | |
| } | |
| if (i >= textArr.length) { | |
| clearInterval(timer) | |
| } | |
| }, 1000) | |
| })(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment