main
reng 4 months ago
parent 5353f5406e
commit 27e81ca002
  1. 65
      vite/src/pages/flow_free.jsx

@ -13,7 +13,6 @@ import VoiceAnalysis from "../comps/voiceanalysis";
import { sendOsc, OSC_ADDRESS, updatePrompt, onOscMessageReceived } from "../util/osc";
import { DebugControl, TEST_PROMPT } from "../comps/debug";
import { useUser } from "../util/useUser";
import { set } from "zod/v4";
const CUELIST_FILE = 'cuelist_demo2.json';
@ -158,7 +157,7 @@ export function FreeFlow(){
onCueEnd();
console.log('Audio ended, ending current cue');
}else{
setChatStatus(ChatStatus.User); // Reset chat status to User after audio ends
// if history contains user input, send it
@ -181,12 +180,15 @@ export function FreeFlow(){
console.error("Audio prompt playback error:", error);
});
refAudioPrompt.current.onended = () => {
console.log('Audio prompt ended, setting chat status to User');
setChatStatus(ChatStatus.User); // Set chat status to User after audio ends
}
}else{
setChatStatus(()=>ChatStatus.User); // Reset chat status to User after audio ends
}
// if(refChatCueEnd.current){
// console.log('Talking ended, ending current cue');
// onCueEnd(); // End the current cue if chat cue has ended
// }
}
}
@ -229,13 +231,13 @@ export function FreeFlow(){
setChatWelcome(true);
resetData(); // Reset data for new conversation
break;
case 'chat_end':
const message= refInput.current?.value?.trim();
console.log('Ending conversation with message:', message);
sendMessage(message, false, true, null);
setChatWelcome(false);
setChatStatus(ChatStatus.Clear);
break;
// case 'chat_end':
// const message= refInput.current?.value?.trim();
// console.log('Ending conversation with message:', message);
// sendMessage(message, false, true, null);
// setChatWelcome(false);
// setChatStatus(ChatStatus.Clear);
// break;
case 'summary':
console.log('Getting summary...');
@ -306,11 +308,11 @@ export function FreeFlow(){
const cue= refCurrentCue.current; // Get the current cue from ref
if(cue.type=='chat'){
// if(chatStatus==ChatStatus.System) {
// console.log('Still talking...');
// refChatCueEnd.current=true;
// return;
// }
if(chatStatus==ChatStatus.System) {
console.log('Still talking...');
refChatCueEnd.current=true;
return;
}
console.log('save chat history:', history);
uploadHistory(history); // Save chat history when cue ends
}
@ -432,7 +434,12 @@ export function FreeFlow(){
if(currentCue?.type!='chat') return; // Only process if current cue is user input
console.log('processSpeech:', finalTranscript);
if(refChatCueEnd.current) {
console.log('Chat cue has ended, do not processing speech');
onCueEnd();
return;
}
if(autoSend && transcript.trim().length > 0) {
console.log('Auto sending transcript:', transcript);
// onCueEnd();
@ -442,12 +449,28 @@ export function FreeFlow(){
console.log('Ending conversation with message:', message);
sendMessage(message, false, false, null);
setChatWelcome(false);
setChatStatus(ChatStatus.Processing); // Set chat status to Processing
}
resetTranscript();
}
}
function manualSendMessage() {
if(currentCue?.type!='chat') return; // Only process if current cue is user input
if(chatStatus!=ChatStatus.User) return; // Only process if chat status is User
const message= refInput.current?.value?.trim();
if(message && message.length>0) {
console.log('Manual sending message:', message);
sendMessage(message, false, false, null);
setChatWelcome(false);
setChatStatus(ChatStatus.Processing); // Set chat status to Processing
}
resetTranscript();
}
useEffect(()=>{
// console.log('Final transcript changed:', finalTranscript);
@ -692,7 +715,7 @@ export function FreeFlow(){
<input type='checkbox' checked={autoSend} onChange={(e) => setAutoSend(e.target.checked)} />
</span>
<button onClick={resetTranscript}>reset transcript</button>
<button onClick={sendMessage} disabled={chatStatus!=ChatStatus.User && chatStatus!=ChatStatus.Message}>Send</button>
<button onClick={manualSendMessage} disabled={chatStatus!=ChatStatus.User && chatStatus!=ChatStatus.Message}>Send</button>
<div className="rounded-2xl bg-gray-300 self-end px-4 tracking-widest">api_status= {status}</div>
<div className="rounded-2xl bg-gray-300 self-end px-4 tracking-widest">chat_status= {chatStatus}</div>

Loading…
Cancel
Save