-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
Summary
Code review identified several duplicate function implementations across the Python codebase that should be consolidated into shared modules.
True Duplicates (should be consolidated)
1. wav_to_array - Exact duplicate
- Locations:
whisper_server/server.py:49andchunking.py:74 - Description: Nearly identical code for converting WAV to numpy array
- Recommendation: Extract to
lib/audio.py
2. read_codec - Exact duplicate
- Locations:
whisper_server/server.py:67andchunking.py:119 - Description: Nearly identical code for reading audio codecs via ffmpeg
- Recommendation: Extract to
lib/audio.py
3. combine_chunks_to_wav - Similar implementation
- Locations:
diarization_worker.py:196andplay.py:103 - Description: Both combine opus chunks into WAV with gap/silence handling
- Recommendation: Extract common logic to shared module
4. mongo_cursor - Duplicate in playground
- Locations:
lib/worker.py:52(shared utility) andplayground.local.py:16 - Recommendation: The playground version should import from
lib/worker
Similar but different (may be intentional)
5. format_eta / _format_eta
stt.py:167returns"02:15:30"formatdiarization_worker.py:127returns"0:15:30"(timedelta string)- Note: Different output formats - may be intentional
6. get_worker_id / _get_worker_id
lib/worker.py:47returns"hostname_pid"processors/vad.py:35returns"py-vad:hostname:pid"(different prefix)- Note: Different formats to distinguish worker types - likely intentional
Proposed Solution
- Create
lib/audio.pywith shared audio functions (wav_to_array,read_codec, potentiallycombine_chunks_to_wav) - Update
whisper_server/server.pyandchunking.pyto import fromlib/audio.py - Fix
playground.local.pyto importmongo_cursorfromlib/worker - Consider consolidating
format_etafunctions if consistent output format is acceptable
Benefits
- Reduced code duplication
- Single source of truth for audio processing utilities
- Easier maintenance and bug fixes
01PrathamS