lesson 7
This commit is contained in:
1 parent
0091c4cf16
commit
9e8aeb04a1
9 files changed
+836
-46
No files matched your search
@@ -0,0 +1,34 @@
|
||||
<template>
|
||||
<span>
|
||||
<span ref="main">
|
||||
<slot />
|
||||
</span>
|
||||
<span>
|
||||
<button type="button" @click="playAudio()">▶️</button>
|
||||
</span>
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useTemplateRef } from "vue";
|
||||
|
||||
const { lang = "ko" } = defineProps<{
|
||||
lang?: string;
|
||||
}>();
|
||||
|
||||
const mainEl = useTemplateRef("main");
|
||||
|
||||
async function playAudio() {
|
||||
if (!mainEl.value) return;
|
||||
const voices = speechSynthesis
|
||||
.getVoices()
|
||||
.filter((v) => v.lang.split(/[-_]/)[0] === lang);
|
||||
if (!voices.length) return;
|
||||
|
||||
const u = new SpeechSynthesisUtterance(mainEl.value.innerText);
|
||||
u.voice = voices[Math.floor(Math.random() * voices.length)];
|
||||
speechSynthesis.speak(u);
|
||||
}
|
||||
</script>
|
||||
|
||||
<style module></style>
|
||||
Reference in new issue
Block a user