/live-translation

live translation of mic input with Amazon Web Services

Primary LanguagePythonMIT LicenseMIT

Issues Stars Forks License

This project is a real-time translation service that captures audio input, translates it using a specified translator, and outputs the translated audio to a specified output device.

Features

  • Real-time Translation: Captures live audio input and translates it instantly.
  • Multiple Output Options: Supports various output options, including Speaker and Mumble.
  • Customizable Translators: Easily switch between different translation services like AWS.

Installation

Prerequisites

  1. Python 3.11+

  2. PortAudio:

    • Windows: No specific installation required; PyAudio includes PortAudio binaries.
      pip install pyaudio
    • Ubuntu: Install PortAudio via package manager:
      sudo apt-get install portaudio19-dev/opus
    • Mac OS X: Install PortAudio using Homebrew:
      brew install portaudio
  3. Opus:

    • Windows: Follow the installation Guide.
    • Linux: Install Opus via package manager (not tested):
      sudo apt-get install libopus0 (Arch Linux opus/lib32-opus)
    • Mac OS X: Install Opus using Homebrew:
      brew install opus
      Then copy the Opus library to /usr/local/lib/:
      sudo mkdir -p /usr/local/lib
      sudo cp $(brew --prefix opus)/lib/libopus.* /usr/local/lib/
  4. pipenv:

    pip install pipenv

Local Development Setup

  1. Clone the repository:

    git clone https://github.com/RaHummel/live-translation.git
    cd live-translation
  2. Create a virtual environment and install dependencies:

    pipenv install

Bundling the Project

To bundle the entire project into a deployable package:

make bundle  // Linux, OS X
.\build.ps1 bundle // Windows

Translators

AWS Translator Setup

Follow the AWS Setup Guide

Supported Languages

Supported languages and voice configurations can be found in the AWS Polly Documentation.

Mumble Setup

For detailed instructions on setting up Mumble, refer to the Mumble Setup Guide

Device Management

To help you identify and configure available audio input and output devices on your system, you can use the List_devices.py script located in the src/helpers directory. This script lists all available devices, which you can then specify in the config.json file for the inputDevice and outputDevice settings.

Listing Devices

  1. Navigate to the src/helpers directory:

    cd src/helpers
  2. Run the List_devices.py script:

    python List_devices.py
  3. The script will output a list of all available audio devices. Use the device names from this list to configure your config.json file.

Example output:

Input Devices:
0. Microphone (Realtek Audio)
1. USB Microphone

Output Devices:
0. Speakers (Realtek Audio)
1. Headphones (USB Audio)

Configuration

The configuration file is located at res/config.json. It allows you to set parameters for the translator, input, and output devices.

Example Configuration:

{
  "inputDevice": "default",
  "output": {
    "mumble": {
      "ipAddress": "localhost",
      "port": 64738,
      "languageChannelMapping": {
        "en": "Channel/Subchannel"
      }
    },
    "speaker": {
      "outputDevice": "default"
    }
  },
  "translator": {
    "aws": {
      "region": "eu-central-1",
      "source_language": {
        "de": "de-DE",
        "en": "en-US"
      },
      "target_language": {
        "en": {
          "language_code": "en-US",
          "voice_id": "Kendra"
        },
        "pl": {
          "language_code": "pl-PL",
          "voice_id": "Jacek"
        },
        "ru": {
          "language_code": "ru-RU",
          "voice_id": "Maxim"
        },
        "de": {
          "language_code": "de-DE",
          "voice_id": "Vicki"
        }
      }
    }
  }
}

Usage

After extracting the bundled zip file to your desired location, run the translation service with the following command:

python main.py 

Command-line Arguments

  • -t, --translator: Translator to use (default: aws)
  • -i, --input: Sound input method to use (default: mic)
  • -o, --output: Sound output method to use (default: mumble)
  • -sl, --source_lang: Source language (default: de)
  • -tl, --target_lang: Target language(s) (default: [en])

Known Issues

  • Opuslib and pymumble: These libraries are no longer maintained. Forked versions are used with necessary modifications.

Contributing

Contributions are welcome! Please fork the repository and submit a pull request.