Files
ko-grammar/docs/.vitepress/theme/components/TTS.vue
T

46 lines
951 B
Vue
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<span>
<span ref="main" :class="class" :lang="lang">
<slot />
</span>
<span>
<button type="button" @click="playAudio()">🗣️</button>
</span>
</span>
</template>
<script setup lang="ts">
import { useTemplateRef } from "vue";
import { speak, getVoices } from "tauri-plugin-tts-api";
const { lang = "ko-KR" } = defineProps<{
class?: string;
lang?: string;
}>();
const mainEl = useTemplateRef("main");
async function playAudio() {
if (!mainEl.value) return;
const voices = await getVoices(lang);
if (!voices.length) return;
const v = voices[Math.floor(Math.random() * voices.length)];
console.log(JSON.stringify(v));
await speak({
text: mainEl.value.innerText
.replace(/[*]/gu, " ")
.replace(/[\p{Ps}\p{Pe}]/gu, ""),
language: null,
rate: null,
volume: null,
pitch: null,
queueMode: null,
voiceId: v.id,
});
}
</script>
<style module></style>