Improve transcription accuracy with overlapping audio chunks
Changes: 1. Changed UI text from "Recording" to "Transcribing" for clarity 2. Implemented overlapping audio chunks to prevent word cutoff Audio Overlap Feature: - Added overlap_duration parameter (default: 0.5 seconds) - Audio chunks now overlap by 0.5s to capture words at boundaries - Prevents missed words when chunks are processed separately - Configurable via audio.overlap_duration in config.yaml How it works: - Each 3-second chunk includes 0.5s from the previous chunk - Buffer advances by (chunk_size - overlap_size) instead of full chunk - Ensures words at chunk boundaries are captured in at least one chunk - No duplicate transcription due to Whisper's context handling Example with 3s chunks and 0.5s overlap: Chunk 1: [0.0s - 3.0s] Chunk 2: [2.5s - 5.5s] <- 0.5s overlap Chunk 3: [5.0s - 8.0s] <- 0.5s overlap Files modified: - client/audio_capture.py: Implemented overlapping buffer logic - config/default_config.yaml: Added overlap_duration setting - gui/main_window_qt.py: Updated UI text, passed overlap param - main_cli.py: Passed overlap param 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -15,6 +15,7 @@ class AudioCapture:
|
||||
self,
|
||||
sample_rate: int = 16000,
|
||||
chunk_duration: float = 3.0,
|
||||
overlap_duration: float = 0.5,
|
||||
device: Optional[int] = None
|
||||
):
|
||||
"""
|
||||
@@ -23,12 +24,15 @@ class AudioCapture:
|
||||
Args:
|
||||
sample_rate: Target audio sample rate in Hz (16000 for Whisper)
|
||||
chunk_duration: Duration of each audio chunk in seconds
|
||||
overlap_duration: Duration of overlap between chunks in seconds (prevents word cutoff)
|
||||
device: Input device index, or None for default
|
||||
"""
|
||||
self.target_sample_rate = sample_rate
|
||||
self.chunk_duration = chunk_duration
|
||||
self.overlap_duration = overlap_duration
|
||||
self.device = device
|
||||
self.chunk_size = int(sample_rate * chunk_duration)
|
||||
self.overlap_size = int(sample_rate * overlap_duration)
|
||||
|
||||
# Hardware sample rate (will be auto-detected)
|
||||
self.hardware_sample_rate = None
|
||||
@@ -156,8 +160,10 @@ class AudioCapture:
|
||||
"""Recording loop that runs in a separate thread."""
|
||||
buffer = np.array([], dtype=np.float32)
|
||||
|
||||
# Calculate hardware chunk size
|
||||
# Calculate hardware chunk and overlap sizes
|
||||
hardware_chunk_size = int(self.hardware_sample_rate * self.chunk_duration)
|
||||
hardware_overlap_size = int(self.hardware_sample_rate * self.overlap_duration)
|
||||
hardware_stride = hardware_chunk_size - hardware_overlap_size
|
||||
|
||||
try:
|
||||
with sd.InputStream(
|
||||
@@ -177,7 +183,10 @@ class AudioCapture:
|
||||
if len(buffer) >= hardware_chunk_size:
|
||||
# Extract chunk
|
||||
chunk = buffer[:hardware_chunk_size]
|
||||
buffer = buffer[hardware_chunk_size:]
|
||||
|
||||
# Move buffer forward by stride (not full chunk size)
|
||||
# This creates overlap between consecutive chunks
|
||||
buffer = buffer[hardware_stride:]
|
||||
|
||||
# Resample to target rate if needed
|
||||
if self.hardware_sample_rate != self.target_sample_rate:
|
||||
|
||||
Reference in New Issue
Block a user