Whisper란?
Whisper는 OpenAI가 공개한 범용 음성 인식(ASR) 모델입니다. 680,000시간의 다국어 데이터로 학습되었으며, 한국어를 포함한 99개 언어를 지원합니다. API로 간편하게 사용하거나, 오픈소스 모델을 로컬에서 실행할 수도 있습니다.
Whisper API 기본 사용법
Python에서 사용하기
from openai import OpenAI
client = OpenAI()
with open("recording.mp3", "rb") as audio_file:
transcript = client.audio.transcriptions.create(
model="whisper-1",
file=audio_file,
language="ko",
response_format="text"
)
print(transcript)
Node.js에서 사용하기
const OpenAI = require('openai');
const fs = require('fs');
const openai = new OpenAI();
async function transcribe(filePath) {
const transcript = await openai.audio.transcriptions.create({
model: 'whisper-1',
file: fs.createReadStream(filePath),
language: 'ko',
response_format: 'verbose_json',
timestamp_granularities: ['segment']
});
transcript.segments.forEach((seg) => {
console.log(\`[\${seg.start.toFixed(1)}s] \${seg.text}\`);
});
return transcript;
}
transcribe('./meeting-recording.mp3');
한국어 정확도 향상 기법
프롬프트 활용
transcript = client.audio.transcriptions.create(
model="whisper-1",
file=audio_file,
language="ko",
prompt="이 회의는 쿠버네티스 클러스터 마이그레이션에 관한 것입니다. "
"참석자: 김영수 팀장, 박지민 선임. "
"주요 키워드: Kubernetes, Helm, ArgoCD, GitOps, Istio"
)
오디오 전처리
from pydub import AudioSegment
def preprocess_audio(input_path, output_path):
audio = AudioSegment.from_file(input_path)
audio = audio.set_channels(1)
audio = audio.set_frame_rate(16000)
from pydub.effects import normalize
audio = normalize(audio)
chunk_ms = 10 * 60 * 1000
chunks = []
for i in range(0, len(audio), chunk_ms):
chunk = audio[i:i + chunk_ms]
chunk_path = f"{output_path}_{i // chunk_ms}.mp3"
chunk.export(chunk_path, format="mp3", bitrate="64k")
chunks.append(chunk_path)
return chunks
실시간 음성 인식 구현
async function startRecording() {
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
const mediaRecorder = new MediaRecorder(stream, {
mimeType: 'audio/webm;codecs=opus'
});
const chunks = [];
mediaRecorder.ondataavailable = (e) => chunks.push(e.data);
mediaRecorder.onstop = async () => {
const blob = new Blob(chunks, { type: 'audio/webm' });
const formData = new FormData();
formData.append('file', blob, 'recording.webm');
const res = await fetch('/api/transcribe', { method: 'POST', body: formData });
const { text } = await res.json();
document.getElementById('result').textContent = text;
};
mediaRecorder.start();
setTimeout(() => mediaRecorder.stop(), 30000);
}
비용 및 제한사항
| 항목 | 내용 |
|---|---|
| 가격 | $0.006 / 분 |
| 파일 크기 제한 | 25MB |
| 지원 형식 | mp3, mp4, mpeg, mpga, m4a, wav, webm |
| 한국어 정확도 | WER ~10-15% (깨끗한 음성 기준) |

댓글 0