// audioRecorder.js export class AudioRecorder { constructor() { this.mediaRecorder = null; this.audioChunks = []; this.onRecordingComplete = null; // 외부 콜백 } start(stream) { this.audioChunks = []; const options = { mimeType: 'audio/webm;codecs=opus' }; this.mediaRecorder = new MediaRecorder(stream, options); this.mediaRecorder.ondataavailable = (event) => { if (event.data.size > 0) { this.audioChunks.push(event.data); } }; this.mediaRecorder.onstop = () => { const audioBlob = new Blob(this.audioChunks, { type: 'audio/webm' }); const audioUrl = URL.createObjectURL(audioBlob); if (this.onRecordingComplete) { this.onRecordingComplete(audioUrl, audioBlob); } }; this.mediaRecorder.start(); console.log('⏺️ Recording started'); } stop() { if (this.mediaRecorder && this.mediaRecorder.state !== 'inactive') { this.mediaRecorder.stop(); console.log('⏹️ Recording stopped'); } } isRecording() { return this.mediaRecorder?.state === 'recording'; } }