import { Card, CardBody } from "@nextui-org/react";
import { langs } from "@uiw/codemirror-extensions-langs";
import ReactCodeMirror from "@uiw/react-codemirror";
export default function InteractiveAvatarCode() {
return (
This SDK supports the following behavior:
-
Start:
Start the
Interactive Avatar session
-
Close:
Close the
Interactive Avatar session
-
);
}
const TEXT = `
export default function App() {
// Media stream used by the video player to display the avatar
const [stream, setStream] = useState ();
const mediaStream = useRef(null);
// Instantiate the Interactive Avatar api using your access token
const avatar = useRef(new StreamingAvatarApi(
new Configuration({accessToken: ''})
));
// State holding Interactive Avatar session data
const [sessionData, setSessionData] = useState();
// Function to start the Interactive Avatar session
async function start(){
const res = await avatar.current.createStartAvatar(
{ newSessionRequest:
// Define the session variables during creation
{ quality: "medium", // low, medium, high
avatarName: ,
voice:{voiceId: }
}
});
setSessionData(res);
}
// Function to stop the Interactive Avatar session
async function stop(){
await avatar.current.stopAvatar({stopSessionRequest: {sessionId: sessionData?.sessionId}});
}
// Function which passes in text to the avatar to repeat
async function handleSpeak(){
await avatar.current.speak({taskRequest: {text: , sessionId: sessionData?.sessionId}}).catch((e) => {
});
}
useEffect(()=>{
// Handles the display of the Interactive Avatar
if(stream && mediaStream.current){
mediaStream.current.srcObject = stream;
mediaStream.current.onloadedmetadata = () => {
mediaStream.current!.play();
}
}
}, [mediaStream, stream])
return (
)
}`;