How Voice-Pro Handles Translation: Azure and Deep Translator Architecture

Voice-Pro implements a dual-provider translation system that automatically selects Microsoft Azure Cognitive Services when credentials are configured, falling back to a free LibreTranslate-based service otherwise.

Voice-Pro translates text through a modular provider pattern defined in the abus-aikorea/voice-pro repository. The implementation abstracts translation logic behind a common interface, allowing the Gradio-based UI controllers to switch between paid and free translation services without changing application code.

Translation Provider Selection Logic

The application determines which translation service to use at runtime by checking for valid Azure credentials before instantiating the appropriate translator class.

Configuration Validation in app/abus_genuine.py

In app/abus_genuine.py, the helper function azure_text_api_working() validates the presence of AZURE_TRANSLATOR_KEY and AZURE_TRANSLATOR_REGION environment variables. This function returns a boolean indicating whether Azure Cognitive Services is properly configured.

from app.abus_genuine import azure_text_api_working

# Runtime check to determine available translation service

if azure_text_api_working():
    translator = AzureTranslator()
else:
    translator = DeepTranslator()

Provider Instantiation in Gradio Controllers

UI controllers such as app/gradio_translate.py, app/gradio_live_translate.py, and app/gradio_gulliver.py implement the selection logic in their constructors. Each controller initializes the translator once during object creation, storing it as self.translator for reuse across user sessions.

from app.abus_genuine import azure_text_api_working
from app.abus_translate_azure import AzureTranslator
from app.abus_translate_deep import DeepTranslator

class GradioTranslate:
    def __init__(self):
        # Select provider based on credential availability

        self.translator = (
            AzureTranslator() if azure_text_api_working() else DeepTranslator()
        )
    
    def translate_click(self, text, src_lang, tgt_lang):
        """Handle translation requests from the UI."""
        translated = self.translator.translate(text, src_lang, tgt_lang)
        return translated

Azure Translator Implementation

The AzureTranslator class in app/abus_translate_azure.py wraps the Azure Cognitive Services Translator REST API. It constructs authenticated HTTP requests to the Microsoft translation endpoint.

import requests
from app.abus_genuine import get_azure_credentials

class AzureTranslator:
    def __init__(self):
        self.key, self.region = get_azure_credentials()
    
    def translate(self, text: str, src: str, tgt: str) -> str:
        url = (
            "https://api.cognitive.microsofttranslator.com/translate"
            f"?api-version=3.0&from={src}&to={tgt}"
        )
        headers = {
            "Ocp-Apim-Subscription-Key": self.key,
            "Ocp-Apim-Subscription-Region": self.region,
            "Content-Type": "application/json"
        }
        response = requests.post(url, headers=headers, json=[{"Text": text}])
        response.raise_for_status()
        return response.json()[0]["translations"][0]["text"]

The method extracts the translated text from the nested JSON response structure returned by Azure's v3.0 API.

Deep Translator Fallback

When Azure credentials are unavailable, Voice-Pro falls back to DeepTranslator defined in app/abus_translate_deep.py. This class utilizes the LibreTranslate public API or compatible endpoints, requiring no authentication keys.

import requests

class DeepTranslator:
    def translate(self, text: str, src: str, tgt: str) -> str:
        url = "https://libretranslate.de/translate"
        payload = {
            "q": text,
            "source": src,
            "target": tgt,
            "format": "text"
        }
        response = requests.post(url, json=payload)
        response.raise_for_status()
        return response.json()["translatedText"]

This implementation provides zero-configuration translation, though with potential rate limits compared to the Azure tier.

UI Integration and Pipeline Usage

Translation is integrated into Voice-Pro's Gradio interface through multiple entry points:

  • app/gradio_translate.py: Standalone text translation tab
  • app/gradio_live_translate.py: Real-time translation during live audio processing
  • app/gradio_gulliver.py: The "Dubbing Studio" tab that translates subtitles before text-to-speech synthesis

In each controller, the translate() method receives source text and language codes, returning the translated string directly to the UI components. The translated output is also written to temporary workspace files for downstream pipeline steps such as TTS (Text-to-Speech) generation.

Configuration Requirements

Azure functionality requires a .env file in the project root with the following variables:

AZURE_TRANSLATOR_KEY=your_subscription_key
AZURE_TRANSLATOR_REGION=your_service_region

If these values are missing or empty, azure_text_api_working() returns False, triggering automatic fallback to the DeepTranslator provider.

Summary

  • Voice-Pro supports two translation providers: Azure Cognitive Services (paid, authenticated) and LibreTranslate-based DeepTranslator (free, unauthenticated).
  • Provider selection occurs at runtime via azure_text_api_working() in app/abus_genuine.py.
  • The common interface translate(text, src, tgt) abstracts provider-specific implementation details from UI controllers.
  • AzureTranslator in app/abus_translate_azure.py implements the Microsoft Translator v3.0 API with proper header authentication.
  • DeepTranslator in app/abus_translate_deep.py provides a zero-key fallback using public LibreTranslate endpoints.
  • Gradio controllers in app/gradio_translate.py and related files instantiate the translator once and reuse it for all user requests.

Frequently Asked Questions

Does Voice-Pro require an Azure subscription for translation?

No. While Voice-Pro supports Azure Cognitive Services for high-quality, authenticated translation, it automatically falls back to the free DeepTranslator service if Azure credentials are not detected in the .env file. The application remains fully functional without paid API keys.

What translation API does Voice-Pro use as a fallback?

The fallback implementation uses LibreTranslate, an open-source machine translation API. The DeepTranslator class in app/abus_translate_deep.py sends POST requests to public LibreTranslate endpoints (such as libretranslate.de) when Azure is unavailable.

How do I add a new translation provider to Voice-Pro?

Create a new Python class implementing the translate(self, text: str, src: str, tgt: str) -> str method signature. Place the file in the app/ directory, then modify the selection logic in app/abus_genuine.py or the Gradio controllers to instantiate your class based on your preferred configuration criteria.

Where is the translation logic triggered in the Voice-Pro UI?

Translation is triggered in multiple Gradio controller files: app/gradio_translate.py handles standalone translation, app/gradio_live_translate.py manages real-time translation during audio streaming, and app/gradio_gulliver.py integrates translation into the dubbing workflow. Each controller calls self.translator.translate() when users click the translate button or during automated pipeline processing.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →