Skip to content

⬅️ Back to Table of Contents

📄 useSpeechSynthesis/demo

📊 Analysis Summary

Metric Count
🔧 Functions 5
📦 Imports 6
📊 Variables & Constants 3
🟢 Vue Composition API 2

📚 Table of Contents

🛠️ File Location:

📂 packages/core/useSpeechSynthesis/demo.vue

📦 Imports

Name Source
useSpeechSynthesis @vueuse/core
computed vue
deepRef vue
onMounted vue
shallowRef vue
watch vue

Variables & Constants

Name Type Kind Value Exported
voice boolean let/var deepRef<SpeechSynthesisVoice>(undefined as unknown as SpeechSynthesisVoice)
synth SpeechSynthesis let/var *not shown*
voices boolean let/var shallowRef<SpeechSynthesisVoice[]>([])

Vue Composition API

Name Type Reactive Variables Composables
computed computed none none
watch watch none none

Functions

onBoundary(event: SpeechSynthesisEvent): void

Parameters:

  • event SpeechSynthesisEvent

Returns: void

Calls:

  • fullText.slice
  • remainingText.match
Code
function onBoundary(event: SpeechSynthesisEvent) {
  const { charIndex, charLength } = event
  const startIndex = charIndex
  let endIndex = charIndex
  if (typeof charLength === 'number' && charLength > 0) {
    endIndex = startIndex + charLength
  }
  else {
    const fullText = text.value || ''
    const remainingText = fullText.slice(startIndex)
    const firstWordMatch = remainingText.match(/^\S+/)
    endIndex = startIndex + (firstWordMatch ? firstWordMatch[0].length : 0)
  }
  boundaryStart.value = startIndex
  boundaryEnd.value = endIndex
}

resetSpeakingText(): void

Returns: void

Code
function resetSpeakingText() {
  boundaryStart.value = 0
  boundaryEnd.value = 0
}

play(): void

Returns: void

Calls:

  • window.speechSynthesis.resume
  • resetSpeakingText
  • speech.speak
Code
function play() {
  if (speech.status.value === 'pause') {
    window.speechSynthesis.resume()
  }
  else {
    resetSpeakingText()
    speech.speak()
  }
}

pause(): void

Returns: void

Calls:

  • window.speechSynthesis.pause
Code
function pause() {
  window.speechSynthesis.pause()
}

stop(): void

Returns: void

Calls:

  • speech.stop
  • resetSpeakingText
Code
function stop() {
  speech.stop()
  resetSpeakingText()
}

Generated by Syntax Scribe