mirror of
https://github.com/Megghy/vtsuru.live.git
synced 2025-12-06 18:36:55 +08:00
fix tts
This commit is contained in:
@@ -132,7 +132,7 @@ async function speak() {
|
||||
speechCount.value--
|
||||
readedDanmaku.value++
|
||||
console.log(`[TTS] 正在朗读: ${text}`)
|
||||
await EasySpeech.speak({
|
||||
/*await EasySpeech.speak({
|
||||
text: text,
|
||||
volume: settings.value.speechInfo.volume,
|
||||
pitch: settings.value.speechInfo.pitch,
|
||||
@@ -150,7 +150,29 @@ async function speak() {
|
||||
})
|
||||
.finally(() => {
|
||||
isSpeaking.value = false
|
||||
})
|
||||
})*/
|
||||
const synth = window.speechSynthesis
|
||||
let u = new SpeechSynthesisUtterance()
|
||||
u.text = text
|
||||
let voices = synth.getVoices()
|
||||
const voice = voices.find((v) => v.name === settings.value.speechInfo.voice)
|
||||
if (voice) {
|
||||
u.voice = voice
|
||||
u.volume = settings.value.speechInfo.volume
|
||||
u.rate = settings.value.speechInfo.rate
|
||||
u.pitch = settings.value.speechInfo.pitch
|
||||
synth.speak(u)
|
||||
u.onend = () => {
|
||||
isSpeaking.value = false
|
||||
}
|
||||
u.onerror = (err) => {
|
||||
if (err.error == 'interrupted') {
|
||||
return
|
||||
}
|
||||
console.log(err)
|
||||
message.error('无法播放语音: ' + err.error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function onGetEvent(data: EventModel) {
|
||||
@@ -219,6 +241,7 @@ function stopSpeech() {
|
||||
}
|
||||
function cancelSpeech() {
|
||||
EasySpeech.cancel()
|
||||
isSpeaking.value = false
|
||||
}
|
||||
async function uploadConfig() {
|
||||
await QueryPostAPI(VTSURU_API_URL + 'set-config', {
|
||||
@@ -351,8 +374,22 @@ onUnmounted(() => {
|
||||
|
||||
<template>
|
||||
<NAlert v-if="!speechSynthesisInfo || !speechSynthesisInfo.speechSynthesis" type="error"> 你的浏览器不支持语音功能 </NAlert>
|
||||
<NSpace v-else>
|
||||
<NButton @click="canSpeech ? stopSpeech() : startSpeech()" :type="canSpeech ? 'error' : 'primary'"> {{ canSpeech ? '停止监听' : '开始监听' }} </NButton>
|
||||
<template v-else>
|
||||
<NAlert type="info">
|
||||
建议在 Edge 浏览器使用
|
||||
<NTooltip>
|
||||
<template #trigger>
|
||||
<NText strong italic type="primary">Microsoft 某某 Online (Nature)</NText>
|
||||
</template>
|
||||
例如 Microsoft Xiaoxiao Online (Natural) - Chinese (Mainland), 各种营销号就用的这些配音
|
||||
</NTooltip>
|
||||
系列语音, 效果要好很多
|
||||
</NAlert>
|
||||
<br />
|
||||
<NSpace>
|
||||
<NButton @click="canSpeech ? stopSpeech() : startSpeech()" :type="canSpeech ? 'error' : 'primary'" data-umami-event="Use TTS" :data-umami-event-uid="accountInfo?.id">
|
||||
{{ canSpeech ? '停止监听' : '开始监听' }}
|
||||
</NButton>
|
||||
<NButton @click="uploadConfig" type="primary" secondary> 保存配置到服务器 </NButton>
|
||||
<NPopconfirm @positive-click="downloadConfig">
|
||||
<template #trigger>
|
||||
@@ -422,6 +459,7 @@ onUnmounted(() => {
|
||||
</NSpace>
|
||||
<NDivider> 设置 </NDivider>
|
||||
<NText depth="3"> 没想好需要什么, 有建议的话可以和我说 </NText>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
<style>
|
||||
|
||||
Reference in New Issue
Block a user