From 5b492f587ee7baecb0f2ddc388fc6c622ba6abe5 Mon Sep 17 00:00:00 2001 From: lushevol Date: Thu, 30 Mar 2023 16:14:31 +0800 Subject: [PATCH] fix: remove react-speech-kit. --- app/components/voice.tsx | 18 +++++++++++++++--- package.json | 1 - yarn.lock | 5 ----- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/components/voice.tsx b/app/components/voice.tsx index 7b3958305..6752f70f4 100644 --- a/app/components/voice.tsx +++ b/app/components/voice.tsx @@ -1,16 +1,26 @@ // implement a voice component by speech synthesis to read the text with the voice of the user's choice import * as React from "react"; import { useState } from "react"; -import { useSpeechSynthesis } from "react-speech-kit"; import { IconButton } from "./button"; import VoiceIcon from "../icons/voice.svg"; const voices = window.speechSynthesis.getVoices(); +const speak = ({ + text, + voice, +}: { + text: string; + voice?: SpeechSynthesisVoice; +}) => { + if (!text) return; + const utterance = new SpeechSynthesisUtterance(text); + utterance.voice = voice || voices[0]; + window.speechSynthesis.speak(utterance); +}; export function Voice(props: { text: string }) { - const { speak } = useSpeechSynthesis(); const [voice, setVoice] = useState(null); - return ( + return props.text ? (
{ @@ -36,5 +46,7 @@ export function Voice(props: { text: string }) { ))}
+ ) : ( + <> ); } diff --git a/package.json b/package.json index 40cc738d6..e8537362a 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,6 @@ "react": "^18.2.0", "react-dom": "^18.2.0", "react-markdown": "^8.0.5", - "react-speech-kit": "^3.0.1", "rehype-katex": "^6.0.2", "rehype-prism-plus": "^1.5.1", "remark-gfm": "^3.0.1", diff --git a/yarn.lock b/yarn.lock index e6ac04775..d4a983989 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4288,11 +4288,6 @@ react-markdown@^8.0.5: unist-util-visit "^4.0.0" vfile "^5.0.0" -react-speech-kit@^3.0.1: - version "3.0.1" - resolved "https://registry.yarnpkg.com/react-speech-kit/-/react-speech-kit-3.0.1.tgz#8bd936adfe064be1c5a07e2992dfdfd772e80d14" - integrity sha512-MXNOciISanhmnxpHJkBOev3M3NPDpW1T7nTc/eGw5pO9cXpoUccRxZkmr/IlpTPbPEneDNeTmbwri/YweyctZg== - react@^18.2.0: version "18.2.0" resolved "https://registry.yarnpkg.com/react/-/react-18.2.0.tgz#555bd98592883255fa00de14f1151a917b5d77d5"