Skip to content

Refactor: ASR Engine Abstraction and Service Layer Cleanup

Prashanth requested to merge refactor/engine-abstraction into develop

🚀 Refactor: Engine Logic Abstraction

📌 Overview

This MR refactors the ASR engine architecture to improve modularity, remove circular dependencies, and enforce a clean separation of concerns. The changes align the system with scalable design principles, making it easier to maintain and extend with new ASR engines.


Problem

The previous architecture had several issues:

  • Circular Dependency

    • SwechaGonthukaEngine depended on asr_service.py, while asr_service.py also depended on engines.
  • God Object

    • asr_service.py handled multiple responsibilities:

      • Transcription logic
      • Audio conversion
      • Punctuation
      • Subtitle generation
  • Inconsistent Engine Design

    • Swecha engine was not self-contained
    • Whisper engine followed a cleaner structure

Solution

This MR introduces a structured refactor:

  • Engine Self-Containment

    • Moved all Swecha-specific logic into SwechaGonthukaEngine
    • Removed dependency on asr_service.py
  • Abstract Engine Interface

    • Introduced AsrEngine base class (app/asr/types.py)

    • Standardized engine contract:

      • transcribe
      • transcribe_pcm16
      • name
      • supported_languages
  • Service Layer Cleanup

    • Removed engine-specific logic from asr_service.py
    • Retained only cross-cutting responsibilities
  • Router Simplification

    • Router now directly calls engine methods
    • Removed dynamic mutation of engine configuration
  • Whisper Engine Refactor

    • Supports constructor-based configuration
    • Improved consistency with Swecha engine
  • Service Extraction

    • Introduced:

      • JobManager → handles async job lifecycle
      • StreamingService → handles WebSocket streaming
    • Reduced responsibility of main.py


🔧 Key Changes

Modified Files

  • app/asr/engines/swecha_gonthuka.py
  • app/asr/engines/whisper.py
  • app/asr/router.py
  • app/asr/types.py
  • app/asr_service.py
  • app/main.py

New Files

  • app/services/job_manager.py
  • app/services/streaming_service.py

🧪 Testing

  • Existing test suite reviewed and executed

  • Verified:

    • Engine routing behavior
    • Batch transcription flow (/transcribe)
    • Streaming functionality (/stream)
  • No regression in API responses


🎯 Impact

  • Eliminates circular dependencies
  • Enforces Single Responsibility Principle
  • Enables easy addition of new ASR engines
  • Improves code readability and maintainability
  • Aligns architecture with scalable backend design

🚫 Out of Scope

  • No changes to ASR models
  • No changes to API contracts
  • No changes to deployment setup

🧠 Summary

This refactor transforms the ASR system into a clean, modular, and extensible architecture by introducing a unified engine interface and decoupling responsibilities across layers.

image

*Closes #17 (closed)

Edited by ashritha kunjeti

Merge request reports

Loading