Move TextToSpeechAudio to a separate file (#800)
This commit is contained in:
parent
35abd517b9
commit
52b0feb255
@ -89,6 +89,7 @@
|
||||
<script src="/mixed/js/scroll.js"></script>
|
||||
<script src="/mixed/js/text-scanner.js"></script>
|
||||
<script src="/mixed/js/template-handler.js"></script>
|
||||
<script src="/mixed/js/text-to-speech-audio.js"></script>
|
||||
|
||||
<script src="/bg/js/query-parser-generator.js"></script>
|
||||
<script src="/bg/js/query-parser.js"></script>
|
||||
|
@ -1172,6 +1172,7 @@
|
||||
<script src="/mixed/js/dom-data-binder.js"></script>
|
||||
<script src="/mixed/js/object-property-accessor.js"></script>
|
||||
<script src="/mixed/js/task-accumulator.js"></script>
|
||||
<script src="/mixed/js/text-to-speech-audio.js"></script>
|
||||
|
||||
<script src="/bg/js/anki.js"></script>
|
||||
<script src="/bg/js/anki-note-builder.js"></script>
|
||||
|
@ -64,6 +64,7 @@
|
||||
<script src="/mixed/js/scroll.js"></script>
|
||||
<script src="/mixed/js/text-scanner.js"></script>
|
||||
<script src="/mixed/js/template-handler.js"></script>
|
||||
<script src="/mixed/js/text-to-speech-audio.js"></script>
|
||||
|
||||
<script src="/bg/js/query-parser-generator.js"></script>
|
||||
<script src="/bg/js/query-parser.js"></script>
|
||||
|
@ -15,55 +15,9 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
class TextToSpeechAudio {
|
||||
constructor(text, voice) {
|
||||
this.text = text;
|
||||
this.voice = voice;
|
||||
this._utterance = null;
|
||||
this._volume = 1;
|
||||
}
|
||||
|
||||
get currentTime() {
|
||||
return 0;
|
||||
}
|
||||
set currentTime(value) {
|
||||
// NOP
|
||||
}
|
||||
|
||||
get volume() {
|
||||
return this._volume;
|
||||
}
|
||||
set volume(value) {
|
||||
this._volume = value;
|
||||
if (this._utterance !== null) {
|
||||
this._utterance.volume = value;
|
||||
}
|
||||
}
|
||||
|
||||
async play() {
|
||||
try {
|
||||
if (this._utterance === null) {
|
||||
this._utterance = new SpeechSynthesisUtterance(this.text || '');
|
||||
this._utterance.lang = 'ja-JP';
|
||||
this._utterance.volume = this._volume;
|
||||
this._utterance.voice = this.voice;
|
||||
}
|
||||
|
||||
speechSynthesis.cancel();
|
||||
speechSynthesis.speak(this._utterance);
|
||||
} catch (e) {
|
||||
// NOP
|
||||
}
|
||||
}
|
||||
|
||||
pause() {
|
||||
try {
|
||||
speechSynthesis.cancel();
|
||||
} catch (e) {
|
||||
// NOP
|
||||
}
|
||||
}
|
||||
}
|
||||
/* global
|
||||
* TextToSpeechAudio
|
||||
*/
|
||||
|
||||
class AudioSystem {
|
||||
constructor({audioUriBuilder, requestBuilder=null, useCache}) {
|
||||
|
66
ext/mixed/js/text-to-speech-audio.js
Normal file
66
ext/mixed/js/text-to-speech-audio.js
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Yomichan Authors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
class TextToSpeechAudio {
|
||||
constructor(text, voice) {
|
||||
this.text = text;
|
||||
this.voice = voice;
|
||||
this._utterance = null;
|
||||
this._volume = 1;
|
||||
}
|
||||
|
||||
get currentTime() {
|
||||
return 0;
|
||||
}
|
||||
set currentTime(value) {
|
||||
// NOP
|
||||
}
|
||||
|
||||
get volume() {
|
||||
return this._volume;
|
||||
}
|
||||
set volume(value) {
|
||||
this._volume = value;
|
||||
if (this._utterance !== null) {
|
||||
this._utterance.volume = value;
|
||||
}
|
||||
}
|
||||
|
||||
async play() {
|
||||
try {
|
||||
if (this._utterance === null) {
|
||||
this._utterance = new SpeechSynthesisUtterance(this.text || '');
|
||||
this._utterance.lang = 'ja-JP';
|
||||
this._utterance.volume = this._volume;
|
||||
this._utterance.voice = this.voice;
|
||||
}
|
||||
|
||||
speechSynthesis.cancel();
|
||||
speechSynthesis.speak(this._utterance);
|
||||
} catch (e) {
|
||||
// NOP
|
||||
}
|
||||
}
|
||||
|
||||
pause() {
|
||||
try {
|
||||
speechSynthesis.cancel();
|
||||
} catch (e) {
|
||||
// NOP
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user