@@ -1107,57 +1107,6 @@ export function useSet(values) {
11071107 return setRef . current ;
11081108}
11091109
1110- export function useSpeech ( text , options ) {
1111- const [ state , setState ] = React . useState ( ( ) => {
1112- const { lang = "default" , name = "" } = options . voice || { } ;
1113- return {
1114- isPlaying : false ,
1115- status : "init" ,
1116- lang : options . lang || "default" ,
1117- voiceInfo : { lang, name } ,
1118- rate : options . rate || 1 ,
1119- pitch : options . pitch || 1 ,
1120- volume : options . volume || 1 ,
1121- } ;
1122- } ) ;
1123-
1124- const optionsRef = React . useRef ( options ) ;
1125-
1126- React . useEffect ( ( ) => {
1127- const handlePlay = ( ) => {
1128- setState ( ( s ) => {
1129- return { ...s , isPlaying : true , status : "play" } ;
1130- } ) ;
1131- } ;
1132-
1133- const handlePause = ( ) => {
1134- setState ( ( s ) => {
1135- return { ...s , isPlaying : false , status : "pause" } ;
1136- } ) ;
1137- } ;
1138-
1139- const handleEnd = ( ) => {
1140- setState ( ( s ) => {
1141- return { ...s , isPlaying : false , status : "end" } ;
1142- } ) ;
1143- } ;
1144-
1145- const utterance = new SpeechSynthesisUtterance ( text ) ;
1146- optionsRef . current . lang && ( utterance . lang = optionsRef . current . lang ) ;
1147- optionsRef . current . voice && ( utterance . voice = optionsRef . current . voice ) ;
1148- utterance . rate = optionsRef . current . rate || 1 ;
1149- utterance . pitch = optionsRef . current . pitch || 1 ;
1150- utterance . volume = optionsRef . current . volume || 1 ;
1151- utterance . onstart = handlePlay ;
1152- utterance . onpause = handlePause ;
1153- utterance . onresume = handlePlay ;
1154- utterance . onend = handleEnd ;
1155- window . speechSynthesis . speak ( utterance ) ;
1156- } , [ text ] ) ;
1157-
1158- return state ;
1159- }
1160-
11611110export function useThrottle ( value , interval = 500 ) {
11621111 const [ throttledValue , setThrottledValue ] = React . useState ( value ) ;
11631112 const lastUpdated = React . useRef ( ) ;
0 commit comments