Skip to content

Commit 65a2f6a

Browse files
committed
Ignore voice recordings shorter than 3 seconds to prevent accidental inputs
1 parent 84e344d commit 65a2f6a

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

‎apps/editor/src/views/panel/backend/message-handlers/handle-voice-input.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ import axios from 'axios'
1313
import { make_api_request } from '@/utils/make-api-request'
1414
import { voice_input_instructions } from '@/constants/instructions'
1515

16+
const MIN_RECORDING_DURATION = 3000
17+
1618
const start_recording = (panel_provider: PanelProvider) => {
1719
panel_provider.audio_chunks = []
20+
panel_provider.recording_start_time = Date.now()
1821
try {
1922
panel_provider.recording_process = spawn('rec', ['-q', '-t', 'wav', '-'])
2023
panel_provider.recording_process.stdout.on('data', (chunk: Buffer) => {
@@ -34,6 +37,14 @@ const stop_recording = async (panel_provider: PanelProvider) => {
3437
panel_provider.recording_process.kill()
3538
panel_provider.recording_process = null
3639

40+
if (
41+
Date.now() - panel_provider.recording_start_time <
42+
MIN_RECORDING_DURATION
43+
) {
44+
panel_provider.audio_chunks = []
45+
return
46+
}
47+
3748
const audio_buffer = Buffer.concat(panel_provider.audio_chunks)
3849
const base64_audio = audio_buffer.toString('base64')
3950

‎apps/editor/src/views/panel/backend/panel-provider.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ export class PanelProvider implements vscode.WebviewViewProvider {
154154
public is_recording = false
155155
public recording_process: ChildProcessWithoutNullStreams | null = null
156156
public audio_chunks: Buffer[] = []
157+
public recording_start_time: number = 0
157158

158159
public preview_switch_choice_resolver:
159160
| ((choice: 'Switch' | undefined) => void)

0 commit comments

Comments
 (0)