말하기 중지
현재 진행 중인 디지털 휴먼의 발화를 즉시 중지합니다.
메서드
stopSpeaking()
현재 진행 중인 발화를 즉시 중지합니다.
public stopSpeaking(): void
사용법
JavaScript/TypeScript
import { KleverOneClient } from "@klever-one/web-sdk/core";
const client = new KleverOneClient({
apiKey: "your-api-key",
container: document.getElementById("streaming-container"),
});
// 연결 후 발화 시작
await client.connect();
client.speak("긴 문장을 말하고 있습니다.");
// 발화 중지
client.stopSpeaking();
React Hook
"use client";
import { useRef, useEffect, useMemo } from "react";
import { useKleverOneClient } from "@klever-one/web-sdk/react";
function SpeechControl() {
const containerRef = useRef(null);
const tempContainer = useMemo(() => {
if (typeof document !== "undefined") {
return document.createElement("div");
}
return {} as HTMLDivElement;
}, []);
const client = useKleverOneClient({
apiKey: "your-api-key",
container: containerRef.current || tempContainer,
callbacks: {
onReady: () => console.log("디지털 휴먼 준비 완료!"),
},
});
useEffect(() => {
return () => {
if (client.client) {
client.disconnect();
}
};
}, [client.client]);
const handleStopSpeaking = () => {
if (client.client) {
client.stopSpeaking();
}
};
return (
<div>
<div
ref={containerRef}
className="h-[400px] w-[800px] bg-black rounded-lg"
></div>
<div className="speech-controls">
<button
onClick={() => client.speak("긴 문장을 말하고 있습니다.")}
disabled={client.state.connection !== "connected"}
>
말하기 시작
</button>
<button
onClick={handleStopSpeaking}
disabled={client.state.connection !== "connected"}
>
말하기 중지
</button>
</div>
</div>
);
}