import { LmComponentRender } from '@LmComponentRender' import React, { useRef } from 'react' // eslint-disable-next-line // @ts-ignore import { useSpeechSynthesis } from 'react-speech-kit' import { LmButtonSpeechTextProps } from './buttonTypes' import { ButtonStoryblok } from '../../typings/generated/components-schema' import { useAppContext } from '@context/AppContext' export default function LmButtonSpeechText({ content }: LmButtonSpeechTextProps) { const { locale } = useAppContext() const ref = useRef(null) const { speak, cancel, speaking, supported, voices } = useSpeechSynthesis() const currentVoices: SpeechSynthesisVoice[] = voices const { full_page, ...props } = content const trigger = Array.isArray(props.trigger) ? props.trigger[0] : undefined const onClick = () => { if (speaking) { cancel() return } const selectedVoice = currentVoices.find((v) => v.lang.startsWith(locale || 'de') ) const allNodes = full_page ? document.querySelectorAll('.enable__speech') || [] : ref.current ?.closest('.lm-section') ?.querySelectorAll('.enable__speech') || [] const texts: string[] = [] allNodes.forEach((node) => { // eslint-disable-next-line // @ts-ignore texts.push(node.innerText) }) speak({ text: texts.join('\n'), voice: selectedVoice }) } if (!supported) { return
not supported..
} return (
) }