Skip to main content

음성 인식 시작

Speech-to-Text(STT) 인식을 시작합니다. 마이크를 활성화하여 사용자의 음성을 녹음합니다.

메서드

startRecording()

음성 녹음을 시작합니다.

public async startRecording(): Promise<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();
await client.startRecording();

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 handleStartRecording = async () => {
try {
await client.startRecording();
console.log("녹음 시작!");
} catch (error) {
console.error("녹음 시작 실패:", error);
}
};

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

다음 단계

녹음을 시작한 후에는:

  • 음성 인식 종료 - 녹음을 중지하고 AI에게 전송
  • 음성 데이터가 자동으로 디지털 휴먼에게 전달됩니다