Skip to main content

음성 인식 종료

Speech-to-Text(STT) 인식을 중단하고 녹음된 음성을 디지털 휴먼에게 전송합니다.

메서드

stopRecording()

녹음을 중지하고 AI에게 전송합니다.

public async stopRecording(): Promise<void>

사용법

JavaScript/TypeScript

import { KleverOneClient } from "@klever/sdk/core";

const client = new KleverOneClient({
apiKey: "your-api-key",
container: document.getElementById("streaming-container"),
});

// 녹음 시작
await client.startRecording();

// 녹음 중지 및 전송
await client.stopRecording();

React Hook

"use client";

import { useRef, useEffect, useMemo } from "react";
import { useKleverOneClient } from "@klever-one/web-sdk/react";

function MyComponent() {
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,
});

useEffect(() => {
return () => {
if (client.client) {
client.disconnect();
}
};
}, [client.client]);

const handleStopRecording = async () => {
try {
await client.stopRecording();
console.log("음성 전송 완료!");
} catch (error) {
console.error("음성 전송 실패:", error);
}
};

return (
<div>
<div
ref={containerRef}
className="h-[400px] w-[800px] bg-black"
></div>
<button
onClick={handleStopRecording}
disabled={client.state.recording !== "recording"}
>
음성 인식 종료
</button>
<p>녹음 상태: {client.state.recording}</p>
</div>
);
}

관련 기능

음성 전송 후에는:

  • 디지털 휴먼이 자동으로 응답을 생성합니다
  • 대화 텍스트 전송 - 텍스트로도 대화 가능
  • 음성 응답은 자동으로 재생됩니다