浏览代码

fix: 聊天声音朗读功能变为静音功能

sheldon 2 月之前
父节点
当前提交
1626aa0da4

+ 2 - 2
src/components/chat-message/MessageRobot.tsx

@@ -179,7 +179,7 @@ export default ({ agent, text, message, showUser=false, textReasoning = "" }: Pr
           }
           }
           
           
         </View>
         </View>
-        {!isReacting && <View className="flex gap-12">
+        <View className="flex gap-12">
           <View onClick={(e) => handleCopy(e, text)}>
           <View onClick={(e) => handleCopy(e, text)}>
             <IconCopy />
             <IconCopy />
           </View>
           </View>
@@ -193,7 +193,7 @@ export default ({ agent, text, message, showUser=false, textReasoning = "" }: Pr
           <View onClick={() => handleLike()}>
           <View onClick={() => handleLike()}>
             {isLike ? <IconLikeBlue /> : <IconLike />}
             {isLike ? <IconLikeBlue /> : <IconLike />}
           </View>
           </View>
-        </View>}
+        </View>
       </View>
       </View>
     </View>
     </View>
   );
   );

+ 10 - 3
src/pages/chat/components/input-bar/chat.ts

@@ -42,6 +42,8 @@ export const useChatInput = ({
     messageSpeakersStopHandle,
     messageSpeakersStopHandle,
     setMessageSpeakersStopHandle,
     setMessageSpeakersStopHandle,
     setReacting,
     setReacting,
+    setScrollTop,
+    setAutoScroll,
   } = useTextChat();
   } = useTextChat();
 
 
   // 聊天框内消息定时上报
   // 聊天框内消息定时上报
@@ -119,8 +121,10 @@ export const useChatInput = ({
       },
       },
       onStart: () => {
       onStart: () => {
         setMessageSpeakersStopHandle(()=> {
         setMessageSpeakersStopHandle(()=> {
-          stopChunk()
-          stopPlay()
+          stopReceiveChunk?.();
+          stopTimedMessage();
+          stopPlayChunk();
+          // setReacting(false)
           const currentRobotMessage = getCurrentRobotMessage();
           const currentRobotMessage = getCurrentRobotMessage();
           if(currentRobotMessage?.content.length === 0){
           if(currentRobotMessage?.content.length === 0){
             deleteMessage(currentRobotMessage.msgUk);
             deleteMessage(currentRobotMessage.msgUk);
@@ -279,7 +283,7 @@ export const useChatInput = ({
   // 如果停止语音输出,则停止播放
   // 如果停止语音输出,则停止播放
   useEffect(() => {
   useEffect(() => {
     if (!enableOutputAudioStream) {
     if (!enableOutputAudioStream) {
-      stopPlayChunk();
+      stopPlay();
     }
     }
   }, [enableOutputAudioStream]);
   }, [enableOutputAudioStream]);
 
 
@@ -290,6 +294,9 @@ export const useChatInput = ({
       stopTimedMessage();
       stopTimedMessage();
       stopPlayChunk();
       stopPlayChunk();
       setReacting(false)
       setReacting(false)
+      setScrollTop(99999);
+      setAutoScroll(true);
+      setMessageSpeakersStopHandle(null)
       console.log('clear chat')
       console.log('clear chat')
     };
     };
   }, []);
   }, []);

+ 6 - 1
src/pages/chat/index.tsx

@@ -49,6 +49,7 @@ export default function Index() {
   });
   });
   const scrollViewRef = useRef<any>(null);
   const scrollViewRef = useRef<any>(null);
   const messageList = useTextChat((state) => state.list);
   const messageList = useTextChat((state) => state.list);
+  const autoScroll = useTextChat((state) => state.autoScroll);
   const [inputContainerHeight,setInputContainerHeight]= useState(0)
   const [inputContainerHeight,setInputContainerHeight]= useState(0)
   const [streamVoiceEnable, setStreamVoiceEnable]= usePersistentState('streamVoiceEnable', false)
   const [streamVoiceEnable, setStreamVoiceEnable]= usePersistentState('streamVoiceEnable', false)
 
 
@@ -163,8 +164,12 @@ const initialScrolledRef = useRef(false);
   // 仅首次 pageIndex === 1 且已经有消息时滚动一次
   // 仅首次 pageIndex === 1 且已经有消息时滚动一次
   if (pageIndex === 1 && messagesLength > 0 && !initialScrolledRef.current) {
   if (pageIndex === 1 && messagesLength > 0 && !initialScrolledRef.current) {
     initialScrolledRef.current = true;
     initialScrolledRef.current = true;
+    
     // 下1秒再滚,确保 DOM 已完成渲染
     // 下1秒再滚,确保 DOM 已完成渲染
-    setTimeout(() => setScrollTop(), 1000);
+    setTimeout(() => {
+      setScrollTop()
+      console.log("首次进入,滚动到底部");
+    }, 1000);
   }
   }
 }, [pageIndex, messagesLength]);
 }, [pageIndex, messagesLength]);
 
 

+ 8 - 2
src/store/textChat.ts

@@ -38,7 +38,7 @@ export interface TextChat {
   setAutoScroll: (b: boolean) => void // 是否自动滚动
   setAutoScroll: (b: boolean) => void // 是否自动滚动
   genSessionId: () => void // 进入聊天界面后,本次的 sessionId
   genSessionId: () => void // 进入聊天界面后,本次的 sessionId
   setQuestions: (q:string[]) => void // 设置推荐问题
   setQuestions: (q:string[]) => void // 设置推荐问题
-  setScrollTop: () => void
+  setScrollTop: (num?: number) => void
   // 将机器人气泡框推入聊天框
   // 将机器人气泡框推入聊天框
   pushRobotMessage: (message: TRobotMessageWithOptionalId) => string;
   pushRobotMessage: (message: TRobotMessageWithOptionalId) => string;
   // 将自己发出的气泡框推入聊天框
   // 将自己发出的气泡框推入聊天框
@@ -144,8 +144,14 @@ export const useTextChat = create<TextChat>((set, get) => ({
     
     
     return {msgUk, sessionId}
     return {msgUk, sessionId}
   },
   },
-  setScrollTop: ()=> {
+  setScrollTop: (num?: number)=> {
+    console.log(get().autoScroll, get().scrollTop, 'xxxxx')
     set((state) => {
     set((state) => {
+      if(num!== undefined){
+        return {
+          scrollTop: num,
+        }
+      }
       if(state.autoScroll){
       if(state.autoScroll){
         return {
         return {
           scrollTop: state.scrollTop + 1,
           scrollTop: state.scrollTop + 1,

+ 1 - 0
src/utils/audioStreamPlayer.ts

@@ -172,6 +172,7 @@ export class AudioStreamPlayer {
 
 
   stopPlay = ()=> {
   stopPlay = ()=> {
     this.source?.stop();
     this.source?.stop();
+    this.enablePlay = false;
   }
   }
 
 
   // 销毁实例
   // 销毁实例