This commit is contained in:
2025-09-19 20:25:02 +09:00
commit dd32bb2ccb
6 changed files with 264 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
// 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';
}
}