|
@@ -458,6 +458,7 @@ export default {
|
|
|
|
|
|
elemType: '',
|
|
|
elemDisc: '',
|
|
|
+ elemAudioId: '',
|
|
|
|
|
|
continueReadTimeoutId: null,
|
|
|
continueReadTaskId: null,
|
|
@@ -733,41 +734,67 @@ export default {
|
|
|
this.mouseDownLastTime = Date.now()
|
|
|
},
|
|
|
planToPlayAudio(taskId, text = '') {
|
|
|
- let XHR = new XMLHttpRequest()
|
|
|
- const that = this
|
|
|
- XHR.onreadystatechange = function() {
|
|
|
- if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
|
|
|
- const res = JSON.parse(this.response)
|
|
|
- if (that.audioPlayer && !that.audioPlayer.ended) {
|
|
|
- that.audioPlayer.pause()
|
|
|
+ if (this.elemAudioId) {
|
|
|
+ if (this.audioPlayer && !this.audioPlayer.ended) {
|
|
|
+ this.audioPlayer.pause()
|
|
|
+ }
|
|
|
+ this.audioPlayer = new Audio('https://culture.4dage.com/one_day_in_southern_song_dynasty_cn_de/media/%E5%8D%88-%E5%8F%A4%E7%90%B4.252acfee.mp3') // todo
|
|
|
+ this.audioPlayer.muted = this.ariaSettings.isMuted
|
|
|
+ this.audioPlayer.playbackRate = speechRateFactors[this.ariaSettings.speechRateLevel]
|
|
|
+ this.audioPlayer.oncanplaythrough = () => {
|
|
|
+ if (document.visibilityState === 'visible') {
|
|
|
+ this.audioPlayer.play()
|
|
|
+ } else {
|
|
|
+ this.$emit('audio-abort', taskId)
|
|
|
}
|
|
|
- that.audioPlayer = new Audio(ajaxOrigin + res.msg)
|
|
|
- that.audioPlayer.muted = that.ariaSettings.isMuted
|
|
|
- that.audioPlayer.playbackRate = speechRateFactors[that.ariaSettings.speechRateLevel]
|
|
|
- that.audioPlayer.oncanplaythrough = () => {
|
|
|
- if (document.visibilityState === 'visible') {
|
|
|
- that.audioPlayer.play()
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ this.audioPlayer.onended = () => {
|
|
|
+ this.$emit('audio-end', taskId)
|
|
|
+ }
|
|
|
+ this.audioPlayer.onerror = (e) => {
|
|
|
+ console.error('audio error!', e)
|
|
|
+ this.$emit('audio-error', taskId)
|
|
|
+ }
|
|
|
+ this.audioPlayer.onabort = () => {
|
|
|
+ this.$emit('audio-abort', taskId)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ let XHR = new XMLHttpRequest()
|
|
|
+ const that = this
|
|
|
+ XHR.onreadystatechange = function() {
|
|
|
+ if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
|
|
|
+ const res = JSON.parse(this.response)
|
|
|
+ if (that.audioPlayer && !that.audioPlayer.ended) {
|
|
|
+ that.audioPlayer.pause()
|
|
|
+ }
|
|
|
+ that.audioPlayer = new Audio(ajaxOrigin + res.msg)
|
|
|
+ that.audioPlayer.muted = that.ariaSettings.isMuted
|
|
|
+ that.audioPlayer.playbackRate = speechRateFactors[that.ariaSettings.speechRateLevel]
|
|
|
+ that.audioPlayer.oncanplaythrough = () => {
|
|
|
+ if (document.visibilityState === 'visible') {
|
|
|
+ that.audioPlayer.play()
|
|
|
+ } else {
|
|
|
+ that.$emit('audio-abort', taskId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ that.audioPlayer.onended = () => {
|
|
|
+ that.$emit('audio-end', taskId)
|
|
|
+ }
|
|
|
+ that.audioPlayer.onerror = (e) => {
|
|
|
+ console.error('audio error!', e)
|
|
|
+ that.$emit('audio-error', taskId)
|
|
|
+ }
|
|
|
+ that.audioPlayer.onabort = () => {
|
|
|
that.$emit('audio-abort', taskId)
|
|
|
}
|
|
|
}
|
|
|
- that.audioPlayer.onended = () => {
|
|
|
- that.$emit('audio-end', taskId)
|
|
|
- }
|
|
|
- that.audioPlayer.onerror = (e) => {
|
|
|
- console.error('audio error!', e)
|
|
|
- that.$emit('audio-error', taskId)
|
|
|
- }
|
|
|
- that.audioPlayer.onabort = () => {
|
|
|
- that.$emit('audio-abort', taskId)
|
|
|
- }
|
|
|
}
|
|
|
+ XHR.open("POST", `${ajaxOrigin}/api/tts/toMp3`)
|
|
|
+ XHR.setRequestHeader("Content-Type", "application/json;charset=UTF-8")
|
|
|
+ XHR.send(JSON.stringify({
|
|
|
+ content: text || this.elemType + (this.elemType ? ': ' : '') + this.elemDisc
|
|
|
+ }))
|
|
|
}
|
|
|
- XHR.open("POST", `${ajaxOrigin}/api/tts/toMp3`)
|
|
|
- XHR.setRequestHeader("Content-Type", "application/json;charset=UTF-8")
|
|
|
- XHR.send(JSON.stringify({
|
|
|
- content: text || this.elemType + (this.elemType ? ': ' : '') + this.elemDisc
|
|
|
- }))
|
|
|
},
|
|
|
keyEventHandler(e) {
|
|
|
if (e.repeat) {
|
|
@@ -912,7 +939,7 @@ export default {
|
|
|
if (extractedText) {
|
|
|
this.elemType = extractedText.elemType
|
|
|
this.elemDisc = extractedText.elemDisc
|
|
|
-
|
|
|
+ this.elemAudioId = extractedText.elemAudioId
|
|
|
this.planToPlayAudio()
|
|
|
}
|
|
|
}, 500),
|
|
@@ -937,6 +964,7 @@ export default {
|
|
|
if (extractedText) {
|
|
|
this.elemType = extractedText.elemType
|
|
|
this.elemDisc = extractedText.elemDisc
|
|
|
+ this.elemAudioId = extractedText.elemAudioId
|
|
|
clearTimeout(this.continueReadTimeoutId)
|
|
|
this.continueReadTimeoutId = setTimeout(() => {
|
|
|
this.continueReadIteratorStoper && this.continueReadIteratorStoper()
|
|
@@ -994,7 +1022,8 @@ export default {
|
|
|
if (extractedText) {
|
|
|
this.elemType = extractedText.elemType
|
|
|
this.elemDisc = extractedText.elemDisc
|
|
|
-
|
|
|
+ this.elemAudioId = extractedText.elemAudioId
|
|
|
+
|
|
|
this.planToPlayAudio(this.continueReadTaskId)
|
|
|
}
|
|
|
},
|