Skip to content

Commit feb764f

Browse files
committed
// Ignore recordings less than 1 second - likely unintentional
1 parent 81c050b commit feb764f

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

llms/ui/modules/chat/index.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,12 +522,20 @@ const VoiceInput = {
522522
if (isProcessing.value) return
523523
try {
524524
const stream = await navigator.mediaDevices.getUserMedia({ audio: true })
525+
recordingStartTime.value = Date.now()
525526
mediaRecorder = new MediaRecorder(stream)
526527
audioChunks = []
527528
mediaRecorder.ondataavailable = event => {
528529
audioChunks.push(event.data)
529530
}
530531
mediaRecorder.onstop = async () => {
532+
// Ignore recordings less than 1 second - likely unintentional
533+
const recordingDuration = Date.now() - recordingStartTime.value
534+
if (recordingDuration < 1000) {
535+
console.debug(`Recording too short (${recordingDuration}ms), ignoring`)
536+
isProcessing.value = false
537+
return
538+
}
531539
const audioBlob = new Blob(audioChunks, { type: 'audio/webm' })
532540
const fileName = `voice-${Date.now()}.webm`
533541

0 commit comments

Comments
 (0)