import { defineStore } from 'pinia'
import Speech from 'speak-tts'

export const useSpeakStore = defineStore('speak', {
  state: () => ({
    ttsStatus: 'idle', // 'idle' | 'playing'
    ttsVoice: '',      // 语音名称，空为默认
    ttsVolume: 1,      // 语音音量
    ttsRate: 1.2,        // 语音语速
    ttsPitch: 1,       // 语音音调
    sendDirectly: true, // 语音转文字后直接发送
    autoTTS: false     // 自动文字语音播报
  }),
  actions: {
    setTTSStatus(status) {
      this.ttsStatus = status
    },
    setTTSVoice(voice) {
      this.ttsVoice = voice
    },
    setSendDirectly(val) {
      this.sendDirectly = val
    },
    setAutoTTS(val) {
      this.autoTTS = val
    },
  },
  persist: {
    key: 'speakStore',
    storage: localStorage,
    paths: ['ttsVoice', 'sendDirectly', 'autoTTS']
  }
})