/* eslint-disable @typescript-eslint/no-unused-vars */ import "./widgets.css"; import { useMemo, useState } from "react"; import { FormattedMessage, useIntl } from "react-intl"; import { NostrLink, NostrPrefix } from "@snort/system"; import Copy from "@/element/copy"; import { useCurrentStreamFeed } from "@/hooks/current-stream-feed"; import { getVoices, speak, toTextToSpeechParams } from "@/text2speech"; import { useLogin } from "@/hooks/login"; import { ZapAlertItem } from "./widgets/zaps"; import { TopZappersWidget } from "./widgets/top-zappers"; import { Views } from "./widgets/views"; import { Music } from "./widgets/music"; import groupBy from "lodash/groupBy"; import { hexToBech32 } from "@snort/shared"; interface ZapAlertConfigurationProps { npub: string; baseUrl: string; } function ZapAlertConfiguration({ npub, baseUrl }: ZapAlertConfigurationProps) { const login = useLogin(); const { formatMessage, formatDisplayName } = useIntl(); const [testText, setTestText] = useState(""); const [textToSpeech, setTextToSpeech] = useState(false); const [voice, setVoice] = useState(null); const [minSatsForTextToSpeech, setMinSatsForTextToSpeech] = useState("21"); const [volume, setVolume] = useState(1); // Google propietary voices are not available on OBS browser const voices = getVoices().filter(v => !v.name.includes("Google")); const groupedVoices = useMemo(() => { return groupBy(voices, v => v.lang); }, [voices]); const languages = useMemo(() => { return Object.keys(groupedVoices).sort(); }, [groupedVoices]); const selectedVoice = useMemo(() => { return voices.find(v => v.voiceURI === voice); }, [voice]); const isTextToSpeechSupported = "speechSynthesis" in window; const isTextToSpeechEnabled = voices.length > 0 && textToSpeech; const query = useMemo(() => { const params = toTextToSpeechParams({ voiceURI: voice, minSats: voice ? Number(minSatsForTextToSpeech) : null, volume, }); const queryParams = params.toString(); return queryParams.length > 0 ? `?${queryParams}` : ""; }, [voice, volume, minSatsForTextToSpeech]); function testVoice() { if (selectedVoice) { speak(selectedVoice, testText, volume); } } return ( <>

setTextToSpeech(!textToSpeech)} style={{ cursor: isTextToSpeechSupported ? "pointer" : "not-allowed" }}> setTextToSpeech(ev.target.checked)} />
{isTextToSpeechEnabled && ( <>
setMinSatsForTextToSpeech(ev.target.value)} />
setVolume(Number(ev.target.value))} />
{voice && ( <>