Updated the InteractiveSpeaking to also work with the session persistence
This commit is contained in:
@@ -53,9 +53,12 @@ export const downloadBlob = async (url: string): Promise<Buffer> => {
|
||||
const evaluateSpeakingExercise = async (exercise: SpeakingExercise, exerciseId: string, solution: UserSolution, id: string) => {
|
||||
const formData = new FormData();
|
||||
|
||||
const audioBlob = await downloadBlob(solution.solutions[0].solution.trim());
|
||||
const url = solution.solutions[0].solution.trim() as string;
|
||||
const audioBlob = await downloadBlob(url);
|
||||
const audioFile = new File([audioBlob], "audio.wav", {type: "audio/wav"});
|
||||
|
||||
if (url && !url.startsWith("blob")) await axios.post("/api/storage/delete", {path: url});
|
||||
|
||||
formData.append("audio", audioFile, "audio.wav");
|
||||
|
||||
const evaluationQuestion =
|
||||
@@ -87,10 +90,15 @@ const evaluateSpeakingExercise = async (exercise: SpeakingExercise, exerciseId:
|
||||
};
|
||||
|
||||
const evaluateInteractiveSpeakingExercise = async (exerciseId: string, solution: UserSolution, id: string) => {
|
||||
const promiseParts = solution.solutions.map(async (x: {prompt: string; blob: string}) => ({
|
||||
question: x.prompt,
|
||||
answer: await downloadBlob(x.blob),
|
||||
}));
|
||||
const promiseParts = solution.solutions.map(async (x: {prompt: string; blob: string}) => {
|
||||
const blob = await downloadBlob(x.blob);
|
||||
if (!x.blob.startsWith("blob")) await axios.post("/api/storage/delete", {path: x.blob});
|
||||
|
||||
return {
|
||||
question: x.prompt,
|
||||
answer: blob,
|
||||
};
|
||||
});
|
||||
const body = await Promise.all(promiseParts);
|
||||
|
||||
const formData = new FormData();
|
||||
@@ -111,6 +119,7 @@ const evaluateInteractiveSpeakingExercise = async (exerciseId: string, solution:
|
||||
};
|
||||
|
||||
const response = await axios.post("/api/evaluate/interactiveSpeaking", formData, config);
|
||||
console.log({data: response.data, status: response.status});
|
||||
|
||||
if (response.status === 200) {
|
||||
return {
|
||||
@@ -120,6 +129,7 @@ const evaluateInteractiveSpeakingExercise = async (exerciseId: string, solution:
|
||||
missing: 0,
|
||||
total: 100,
|
||||
},
|
||||
module: "speaking",
|
||||
solutions: [{id: exerciseId, solution: response.data ? response.data.answer : null, evaluation: response.data}],
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user