-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhraseComponent.vue
78 lines (77 loc) · 2.19 KB
/
PhraseComponent.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<template>
<div class="grid grid-cols-1 md:grid-cols-2 my-1 mx-4 p-1" :class="class">
<div>
<div class="flex items-center">
<button
class="rounded-full p-2 border hover:bg-gray-100"
type="button"
@click="speakKorean(props.item.korean)"
>
<IconSpeakerWave />
</button>
<div class="ml-4">
<p>{{ props.item.korean }}</p>
<p v-if="props.romanization">
{{ props.item.read }}
</p>
</div>
</div>
</div>
<div>
<div class="flex items-center">
<button
v-if="props.english"
class="rounded-full p-2 border hover:bg-gray-100"
type="button"
@click="speakEnglish(props.item.english)"
>
<IconSpeakerWave />
</button>
<div class="ml-4">
<p v-if="props.english">{{ props.item.english }}</p>
<p v-if="props.lao">{{ props.item.lao }}</p>
</div>
</div>
</div>
</div>
</template>
<script setup lang="ts">
const props = defineProps({
item: {
type: Object,
default: () => {},
},
english: {
type: Boolean,
default: true,
},
lao: {
type: Boolean,
default: true,
},
romanization: {
type: Boolean,
default: true,
},
speechRate: {
type: Number,
default: 1,
},
class: {
type: String,
default: "",
},
});
function speakKorean(text: string) {
const utterance = new SpeechSynthesisUtterance(text);
utterance.lang = "ko-KR"; // Korean language
utterance.rate = props.speechRate;
window.speechSynthesis.speak(utterance);
}
function speakEnglish(text: string) {
const utterance = new SpeechSynthesisUtterance(text);
utterance.lang = "en-US"; // English language
utterance.rate = props.speechRate;
window.speechSynthesis.speak(utterance);
}
</script>