| 12
 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
 
 | import { defineStore } from 'pinia';
 const voiceNames = {
 'en': 'Aaron',
 'zh-TW': 'Google 國語(臺灣)',
 };
 
 export const useSpeechSynthesisStore = defineStore('speechSynthesis', () => {
 const lang = ref('zh-TW');
 const voices = ref([]);
 const voice = ref();
 const content = ref();
 
 const {
 isPlaying,
 isSupported,
 speak,
 stop,
 } = useSpeechSynthesis(content, {
 lang,
 voice,
 });
 
 
 setTimeout(() => {
 voices.value = window.speechSynthesis.getVoices();
 voice.value = voices.value.find(voice => voice.name === voiceNames[lang.value]);
 }, 100);
 
 const setContent = (value) => {
 content.value = value;
 };
 
 const start = (content) => {
 setContent(content);
 speak();
 };
 
 watch(lang, (after) => {
 voice.value = voices.value.find(voice => voice.name === voiceNames[after]);
 });
 
 return {
 lang,
 content,
 isPlaying,
 isSupported,
 setContent,
 speak: start,
 stop,
 };
 });
 
 |