main
reng 4 months ago
parent e364c0dbb6
commit 1dd02a36ca
  1. 4
      vite/public/cuelist_demo2.json
  2. 23
      vite/src/pages/flow_free.jsx
  3. 2
      vite/src/util/backend.js
  4. 12
      vite/src/util/useUser.jsx

@ -76,7 +76,7 @@
"type": "chat",
"description": "chat",
"auto": true,
"nextcue": 4.3,
"nextcue": 4.21,
"duration": 90,
"status":"go"
},
@ -105,7 +105,7 @@
"description": "準備打電話",
"audioFile": "assets/record/record-03.mp3",
"auto": true,
"nextcue": 5.1
"nextcue": 4.5
},
{
"id": 4.5,

@ -49,13 +49,8 @@ export function FreeFlow(){
const [chatWelcome, setChatWelcome] = useState(null);
const [audioInput, setAudioInput] = useState(true);
const [autoSend, setAutoSend] = useState(true);
// const [userId, setUserId] = useState();
const [summary, setSummary] = useState(null);
// const [voice, setVoice] = useState(Voice.ONYX);
//const [speechPaused, setSpeechPaused]=useState(false);
const [chatStatus, setChatStatus] = useState(ChatStatus.System); // System, User, Processing
const { userId, setUserId, getFileId, setPassword, reset:resetUser, uploadHistory } = useUser();
const { userId, setUserId, getFileId, setPassword, reset:resetUser, uploadHistory, setSummary, summary,setChoice } = useUser();
const refTimer=useRef();
const refAudio=useRef();
@ -70,7 +65,8 @@ export function FreeFlow(){
const refCurrentCue= useRef(null);
const { history, status, reset, sendMessage, setStatus, audioOutput, setAudioOutput, stop:stopChat, audioUrl, }=useChat();
const { history, status, reset, sendMessage, setStatus, audioOutput, setAudioOutput, stop:stopChat,
audioUrl }=useChat();
const {
@ -217,11 +213,11 @@ export function FreeFlow(){
console.log('Summary:', summary_);
onCueEnd(); // End the current cue after getting summary
setSummary(summary_);
setSummary(summary_?.result);
refContainer.current.scrollTop = refContainer.current.scrollHeight; // Scroll to bottom
// sendOsc(OSC_ADDRESS.SUMMARY, summary_?.result);
sendOsc(OSC_ADDRESS.SAVE, `${getFileId()}#${summary_?.result}`); // Save summary with file ID
// sendOsc(OSC_ADDRESS.EXPORT, `${getFileId()}#${summary_?.result}#${password}`); // Save summary with file ID
}).catch(error => {
console.error('Error getting summary:', error);
@ -230,7 +226,7 @@ export function FreeFlow(){
break;
case 'user_input':
console.log('User input cue, setting chat status to User');
setChatStatus(ChatStatus.User); // Set chat status to User for user input cues
setChatStatus(ChatStatus.Clear); // Set chat status to User for user input cues
resetTranscript(); // Reset transcript for user input
break;
}
@ -284,7 +280,6 @@ export function FreeFlow(){
refChatCueEnd.current=true;
return;
}
uploadHistory(history); // Save chat history when cue ends
}
@ -338,11 +333,13 @@ export function FreeFlow(){
setUserId(()=>mess);
break;
case NUMPAD_TYPE.CHOICE:
next=cue.branch[mess.toString()].nextcue;
next=cue.branch[mess.toString()].nextcue;
setChoice(cue.branch[mess.toString()].description); // Set choice for user input
break;
case NUMPAD_TYPE.PASSWORD:
setPassword(()=>mess);
sendOsc(OSC_ADDRESS.PASSWORD, mess); // Send OSC password message
// sendOsc(OSC_ADDRESS.PASSWORD, mess); // Send OSC password message
sendOsc(OSC_ADDRESS.EXPORT, `${getFileId()}#${summary}#${mess}`);
sendOsc(OSC_ADDRESS.CHOICE, OSC_ADDRESS.SAVE); // Send OSC save choice message
break;
}

@ -24,7 +24,7 @@ export async function updateUser(id, data){
}
try{
const db = getFirestore(app);
await setDoc(doc(db, CollectionName, id), data);
await setDoc(doc(db, CollectionName, id), data, { merge: true });
console.log("Document successfully written!");

@ -19,6 +19,8 @@ export function UserProvider({children}) {
const [userId, setUserId] = useState(null);
const [sessionId, setSessionId] = useState(null);
const [password, setPassword] = useState(null);
const [choice, setChoice] = useState(null);
const [summary, setSummary] = useState(null);
function getFileId(){
@ -55,6 +57,8 @@ export function UserProvider({children}) {
userId,
sessionId,
password,
choice,
summary,
date: moment().format("YYYY-MM-DD"),
fileId: getFileId(),
};
@ -69,7 +73,7 @@ export function UserProvider({children}) {
console.error("Error updating user data:", error);
});
},[password, sessionId]);
},[password, sessionId, choice, summary]);
useEffect(() => {
@ -90,7 +94,11 @@ export function UserProvider({children}) {
}, [userId]);
return (
<userContext.Provider value={{ userId, setUserId, getFileId, setPassword, reset, uploadHistory: saveHistory }}>
<userContext.Provider value={{
userId, setUserId, getFileId,
reset, uploadHistory: saveHistory, setChoice,
setSummary, summary,
setPassword}}>
{children}
</userContext.Provider>
);

Loading…
Cancel
Save