Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean test #50

Merged
merged 6 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ name: Azure Static Web Apps CI/CD
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened, closed]
branches:
- main
-cleanTest

jobs:
build_and_deploy_job:
Expand Down
5 changes: 1 addition & 4 deletions src/conference-ia/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
'no-unused-vars': 'warn',
},
}
2 changes: 1 addition & 1 deletion src/conference-ia/src/Components/Carousel.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect } from 'react';
import { useState, useEffect } from 'react';

function Carousel({ imagesUrls }: { imagesUrls: string[] }) {
const [currentImageIndex, setCurrentImageIndex] = useState<number>(0);
Expand Down
36 changes: 3 additions & 33 deletions src/conference-ia/src/Components/CreateConference.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,10 @@ import { Link } from 'react-router-dom';

const CreateConference: React.FC = () => {
const [title, setTitle] = useState('');
const [isLoading, setIsLoading] = useState(false);
const [message, setMessage] = useState('');
const [isLoading] = useState(false);
const [message] = useState('');

const handleSubmit = async (event: React.FormEvent) => {
event.preventDefault();

if (!title || !title.trim()) {
setMessage('Vous devez écrire un contexte.');
return;
}

setIsLoading(true);
setMessage('Création en cours...');

try {
const response = await fetch('https://api-generateconference.azurewebsites.net/Conference/CreateConference', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ Prompt: title })
});

if (response.ok) {
setMessage('La conférence a été créée.');
} else {
setMessage('La création de la conférence a échoué.');
}
} catch (error) {
setMessage('Une erreur est survenue lors de la création de la conférence.');
} finally {
setIsLoading(false);
}
};
// eslint-disable-next-line @typescript-eslint/no-unused-vars

return (
<div className="flex flex-col items-center justify-center min-h-screen bg-gray-100 space-y-10">
Expand Down
300 changes: 150 additions & 150 deletions src/conference-ia/src/Components/Non Utilisé/Avatar.tsx
Original file line number Diff line number Diff line change
@@ -1,156 +1,156 @@
import React, { useState, useRef, useEffect } from "react";
import "../css/Avatar.css";
import * as SpeechSDK from "microsoft-cognitiveservices-speech-sdk";
import { createAvatarSynthesizer, createWebRTCConnection } from "./Utility";
import { avatarAppConfig } from "./config";
import Carousel from "../Carousel";
import DescriptionSpot from "../DescriptionSpot";
import TextToSpeech from "../TextToSpeech";

interface AvatarProps {
conferenceText: string;
images : string[];
}

const Avatar = ({ conferenceText, images }: AvatarProps) => {
const [avatarSynthesizer, setAvatarSynthesizer] = useState<any>(null);
const myAvatarVideoRef = useRef<HTMLDivElement>(null);
const myAvatarVideoEleRef = useRef<HTMLVideoElement>(null);
const myAvatarAudioEleRef = useRef<HTMLAudioElement>(null);
const [description, setDescription] = useState<string>("");
const [isAvatarStarted, setIsAvatarStarted] = useState<boolean>(false);
const iceUrl = avatarAppConfig.iceUrl;
const iceUsername = avatarAppConfig.iceUsername;
const iceCredential = avatarAppConfig.iceCredential;

const handleOnTrack = (event: any) => {
console.log("#### Printing handle onTrack ", event);
console.log("Printing event.track.kind ", event.track.kind);
if (event.track.kind === "video") {
const mediaPlayer = myAvatarVideoEleRef.current;
mediaPlayer!.id = event.track.kind;
mediaPlayer!.srcObject = event.streams[0];
mediaPlayer!.autoplay = true;
mediaPlayer!.playsInline = true;
mediaPlayer!.addEventListener("play", () => {
window.requestAnimationFrame(() => {});
});
} else {
const audioPlayer = myAvatarAudioEleRef.current;
audioPlayer!.srcObject = event.streams[0];
audioPlayer!.autoplay = true;
audioPlayer!.muted = true;
}
};

const stopSession = () => {
try {
avatarSynthesizer.stopSpeakingAsync().then(() => {
console.log("[" + new Date().toISOString() + "] Stop speaking request sent.");
avatarSynthesizer.close();
}).catch((error: any) => {
console.error(error);
});
} catch (e) {
console.error(e);
}
};

const speakSelectedText = (text : string) => {
if (!avatarSynthesizer) {
console.error("Avatar synthesizer is not initialized.");
return;
}

const audioPlayer = myAvatarAudioEleRef.current;
audioPlayer!.muted = false;

avatarSynthesizer.speakTextAsync(text).then((result: any) => {
if (result.reason === SpeechSDK.ResultReason.SynthesizingAudioCompleted) {
console.log("Speech and avatar synthesized to video stream.");
setIsAvatarStarted(true);
} else {
console.log("Unable to speak. Result ID: " + result.resultId);
if (result.reason === SpeechSDK.ResultReason.Canceled) {
let cancellationDetails = SpeechSDK.CancellationDetails.fromResult(result);
console.log(cancellationDetails.reason);
if (cancellationDetails.reason === SpeechSDK.CancellationReason.Error) {
console.log(cancellationDetails.errorDetails);
}
}
}
}).catch((error: any) => {
console.error(error);
if (avatarSynthesizer) {
avatarSynthesizer.close();
}
});
};


const startSession = async () => {
let peerConnection = createWebRTCConnection(
iceUrl,
iceUsername,
iceCredential
);
peerConnection.ontrack = handleOnTrack;
peerConnection.addTransceiver('video', { direction: 'sendrecv' });
peerConnection.addTransceiver('audio', { direction: 'sendrecv' });

let avatarSynthesizer = createAvatarSynthesizer();
setAvatarSynthesizer(avatarSynthesizer);
avatarSynthesizer
.startAvatarAsync(peerConnection)
.then((r) => {
if (r.reason === SpeechSDK.ResultReason.SynthesizingAudioCompleted) {
console.log("Speech and avatar synthesized to video stream.");
}
console.log('[' + new Date().toISOString() + '] Avatar started.');
setIsAvatarStarted(true);
})
.catch((error) => {
console.log(
'[' +
new Date().toISOString() +
'] Avatar failed to start. Error: ' +
error
);
});
};



useEffect(() => {
startSession();
}, []);


useEffect(() => {
setTimeout(setDescription, 1000,conferenceText);
}, [isAvatarStarted]);


useEffect(() => {
if (description) {
speakSelectedText(conferenceText);
}
}, [description]);

return (
<div className="container myAvatarContainer flex-row">
<div className="container myAvatarVideoRootDiv d-flex justify-content-between">
// import { useState, useRef, useEffect } from "react";
// import "../css/Avatar.css";
// import * as SpeechSDK from "microsoft-cognitiveservices-speech-sdk";
// import { createAvatarSynthesizer, createWebRTCConnection } from "./Utility";
// import { avatarAppConfig } from "./config";
// import Carousel from "../Carousel";
// import DescriptionSpot from "../DescriptionSpot";
// import TextToSpeech from "../TextToSpeech";

// interface AvatarProps {
// conferenceText: string;
// images : string[];
// }

// const Avatar = ({ conferenceText, images }: AvatarProps) => {
// const [avatarSynthesizer, setAvatarSynthesizer] = useState<any>(null);
// const myAvatarVideoRef = useRef<HTMLDivElement>(null);
// const myAvatarVideoEleRef = useRef<HTMLVideoElement>(null);
// const myAvatarAudioEleRef = useRef<HTMLAudioElement>(null);
// const [description, setDescription] = useState<string>("");
// const [isAvatarStarted, setIsAvatarStarted] = useState<boolean>(false);
// const iceUrl = avatarAppConfig.iceUrl;
// const iceUsername = avatarAppConfig.iceUsername;
// const iceCredential = avatarAppConfig.iceCredential;

// const handleOnTrack = (event: any) => {
// console.log("#### Printing handle onTrack ", event);
// console.log("Printing event.track.kind ", event.track.kind);
// if (event.track.kind === "video") {
// const mediaPlayer = myAvatarVideoEleRef.current;
// mediaPlayer!.id = event.track.kind;
// mediaPlayer!.srcObject = event.streams[0];
// mediaPlayer!.autoplay = true;
// mediaPlayer!.playsInline = true;
// mediaPlayer!.addEventListener("play", () => {
// window.requestAnimationFrame(() => {});
// });
// } else {
// const audioPlayer = myAvatarAudioEleRef.current;
// audioPlayer!.srcObject = event.streams[0];
// audioPlayer!.autoplay = true;
// audioPlayer!.muted = true;
// }
// };

// const stopSession = () => {
// try {
// avatarSynthesizer.stopSpeakingAsync().then(() => {
// console.log("[" + new Date().toISOString() + "] Stop speaking request sent.");
// avatarSynthesizer.close();
// }).catch((error: any) => {
// console.error(error);
// });
// } catch (e) {
// console.error(e);
// }
// };

// const speakSelectedText = (text : string) => {
// if (!avatarSynthesizer) {
// console.error("Avatar synthesizer is not initialized.");
// return;
// }

// const audioPlayer = myAvatarAudioEleRef.current;
// audioPlayer!.muted = false;

// avatarSynthesizer.speakTextAsync(text).then((result: any) => {
// if (result.reason === SpeechSDK.ResultReason.SynthesizingAudioCompleted) {
// console.log("Speech and avatar synthesized to video stream.");
// setIsAvatarStarted(true);
// } else {
// console.log("Unable to speak. Result ID: " + result.resultId);
// if (result.reason === SpeechSDK.ResultReason.Canceled) {
// let cancellationDetails = SpeechSDK.CancellationDetails.fromResult(result);
// console.log(cancellationDetails.reason);
// if (cancellationDetails.reason === SpeechSDK.CancellationReason.Error) {
// console.log(cancellationDetails.errorDetails);
// }
// }
// }
// }).catch((error: any) => {
// console.error(error);
// if (avatarSynthesizer) {
// avatarSynthesizer.close();
// }
// });
// };


// const startSession = async () => {
// let peerConnection = createWebRTCConnection(
// iceUrl,
// iceUsername,
// iceCredential
// );
// peerConnection.ontrack = handleOnTrack;
// peerConnection.addTransceiver('video', { direction: 'sendrecv' });
// peerConnection.addTransceiver('audio', { direction: 'sendrecv' });

// let avatarSynthesizer = createAvatarSynthesizer();
// setAvatarSynthesizer(avatarSynthesizer);
// avatarSynthesizer
// .startAvatarAsync(peerConnection)
// .then((r) => {
// if (r.reason === SpeechSDK.ResultReason.SynthesizingAudioCompleted) {
// console.log("Speech and avatar synthesized to video stream.");
// }
// console.log('[' + new Date().toISOString() + '] Avatar started.');
// setIsAvatarStarted(true);
// })
// .catch((error) => {
// console.log(
// '[' +
// new Date().toISOString() +
// '] Avatar failed to start. Error: ' +
// error
// );
// });
// };



// useEffect(() => {
// startSession();
// }, []);


// useEffect(() => {
// setTimeout(setDescription, 1000,conferenceText);
// }, [isAvatarStarted]);


// useEffect(() => {
// if (description) {
// speakSelectedText(conferenceText);
// }
// }, [description]);

// return (
// <div className="container myAvatarContainer flex-row">
// <div className="container myAvatarVideoRootDiv d-flex justify-content-between">

<Carousel imagesUrls={images} />
// <Carousel imagesUrls={images} />

<TextToSpeech content={conferenceText} />
// <TextToSpeech content={conferenceText} />

<DescriptionSpot description={description} />
// <DescriptionSpot description={description} />

</div>
</div>
);
// </div>
// </div>
// );

};
// };

export default Avatar;
// export default Avatar;
Loading
Loading