|
| 1 | +# Tutorial: Deploying MeloTTS on Android using Termux + proot Debian + Micromamba |
| 2 | + |
| 3 | +MeloTTS is designed to be lightweight and efficient, making it an viable choice for deployment on Android devices. |
| 4 | + |
| 5 | +This guide details how to install and run MeloTTS on an Android device using Termux, a Debian environment managed by `proot-distro`, and Micromamba for isolated Python environment management. |
| 6 | + |
| 7 | +**Disclaimer:** This setup is primarily for experimental purposes, don't use it for production. |
| 8 | + |
| 9 | +## Prerequisites |
| 10 | + |
| 11 | +1. **Android Device:** A reasonably capable Android phone. (recommended to use flagship phones released after 2022) |
| 12 | + - **Important for Android 12+ users:** Before installing Termux, you should disable phantom process killing to prevent background processes from being terminated unexpectedly. This requires either root access or ADB with proper permissions. See the [Troubleshooting section](#troubleshooting-and-tips) for detailed instructions. |
| 13 | +2. **Termux App:** Installed on your device. Download the latest release from the [official GitHub repository](https://github.com/termux/termux-app/releases) |
| 14 | +3. **Internet Connection** |
| 15 | +4. **Storage Space:** Sufficient free space for Termux, Debian rootfs, Micromamba environments, Python dependencies (PyTorch), and MeloTTS source/models |
| 16 | +5. **Basic Linux Command Line Familiarity:** Helpful |
| 17 | + |
| 18 | +## Step 1: Install and Prepare Termux |
| 19 | + |
| 20 | +1. **Download and Install Termux:** Go to the [Termux GitHub Releases page](https://github.com/termux/termux-app/releases), download the latest `.apk` file appropriate for your device's architecture (usually `arm64-v8a`), and install it. Enable installation from unknown sources in Android settings if needed. |
| 21 | +2. **Open Termux.** |
| 22 | +3. **Update and upgrade Termux packages:** Run this command and answer `Y` (yes) to any prompts. |
| 23 | + ```bash |
| 24 | + pkg update && pkg upgrade -y |
| 25 | + ``` |
| 26 | +4. **Install `proot-distro`, `git`, and `curl`:** `proot-distro` manages Linux distributions, `git` clones repositories, and `curl` downloads files. |
| 27 | + ```bash |
| 28 | + pkg install proot-distro git curl -y |
| 29 | + ``` |
| 30 | +5. **Grant Storage Access:** Allows Termux/Debian to access your phone's shared storage. |
| 31 | + ```bash |
| 32 | + termux-setup-storage |
| 33 | + ``` |
| 34 | + Confirm the permission request from Android. Shared storage is typically at `~/storage/shared/`. |
| 35 | + |
| 36 | +## Step 2: Install Debian Environment |
| 37 | + |
| 38 | +1. **Install Debian using `proot-distro`:** Downloads the Debian filesystem. |
| 39 | + ```bash |
| 40 | + proot-distro install debian |
| 41 | + ``` |
| 42 | + |
| 43 | +## Step 3: Enter Debian, Install Micromamba and System Dependencies |
| 44 | + |
| 45 | +1. **Log in to Debian:** |
| 46 | + ```bash |
| 47 | + proot-distro login debian |
| 48 | + ``` |
| 49 | + Your prompt should change (e.g., `root@localhost:~#`). **All subsequent commands in Steps 3-5 are run inside this Debian environment unless stated otherwise.** |
| 50 | +2. **Update Debian's package list and upgrade packages:** |
| 51 | + ```bash |
| 52 | + apt update && apt upgrade -y |
| 53 | + ``` |
| 54 | +3. **Install essential build tools and runtime dependencies:** |
| 55 | + ```bash |
| 56 | + yes | apt install build-essential libsndfile1 ffmpeg curl bzip2 git nano mecab libmecab-dev mecab-ipadic-utf8 |
| 57 | + ``` |
| 58 | +4. **Install Micromamba:** Run the official installation script. |
| 59 | + ```bash |
| 60 | + "${SHELL}" <(curl -L micro.mamba.pm/install.sh) |
| 61 | + ``` |
| 62 | + *Follow any on-screen instructions. Defaults are usually fine.* |
| 63 | +5. **Initialize Shell for Micromamba:** Ensure the `micromamba` command is accessible. |
| 64 | + ```bash |
| 65 | + source ~/.bashrc |
| 66 | + ``` |
| 67 | + *(Or exit and re-login to Debian: `exit`, then `proot-distro login debian`)*. |
| 68 | +6. **Verify Micromamba Installation:** |
| 69 | + ```bash |
| 70 | + micromamba --version |
| 71 | + ``` |
| 72 | + |
| 73 | +## Step 4: Create Micromamba Environment and Install MeloTTS |
| 74 | + |
| 75 | +1. **Create a dedicated environment:** Use Python 3.10. |
| 76 | + ```bash |
| 77 | + micromamba create -n melotts python=3.10 -c conda-forge -y |
| 78 | + ``` |
| 79 | +2. **Activate the environment:** **Crucial step before proceeding.** |
| 80 | + ```bash |
| 81 | + micromamba activate melotts |
| 82 | + ``` |
| 83 | + Your prompt should now be prefixed with `(melotts)`. |
| 84 | +3. **Clone the MeloTTS Repository:** Navigate to a suitable directory (e.g., `~/`) and clone the repo. |
| 85 | + ```bash |
| 86 | + # Example: Clone into ~/MeloTTS |
| 87 | + cd ~ |
| 88 | + git clone https://github.com/not-hanjo-mei/MeloTTS.git |
| 89 | + ``` |
| 90 | +4. **Navigate into the Cloned Directory:** |
| 91 | + ```bash |
| 92 | + cd MeloTTS |
| 93 | + ``` |
| 94 | +5. **Install MeloTTS and Dependencies:** |
| 95 | + ```bash |
| 96 | + pip install -e . |
| 97 | + ``` |
| 98 | +6. **Download Japanese Dictionary Data (UniDic):** |
| 99 | + ```bash |
| 100 | + python -m unidic download |
| 101 | + ``` |
| 102 | +7. ***(Optional) Install eunjeon (for Korean support):*** |
| 103 | + ```bash |
| 104 | + pip install eunjeon python-mecab-ko python-mecab-ko-dic |
| 105 | + ``` |
| 106 | +8. **Download NLTK tagger:** |
| 107 | + ```bash |
| 108 | + python -m nltk.downloader averaged_perceptron_tagger_eng |
| 109 | + ``` |
| 110 | + If the NLTK download fails, try this alternative method: |
| 111 | + ```bash |
| 112 | + # Ensure you're in the MeloTTS directory and have NLTK installed |
| 113 | + python webapi/nltk_res.py |
| 114 | + ``` |
| 115 | +## Step 5: Use MeloTTS (Inside Activated Environment) |
| 116 | + |
| 117 | +**IMPORTANT:** Ensure the `melotts` environment is active (`micromamba activate melotts`). Check for the `(melotts)` prefix in your prompt. |
| 118 | + |
| 119 | +**Note:** Example scripts and test resources are available in the `test/` directory of the MeloTTS repository. You can use these files (such as `test_base_model_tts_package.py` and various example text files) to quickly verify your installation or experiment with the TTS functionality. See the contents of the `test/` folder for ready-to-use scripts and sample inputs. |
| 120 | + |
| 121 | +For the latest and most detailed usage instructions (including WebUI, CLI, and Python API), please refer to the **Usage** section in [install.md](./install.md#usage). |
| 122 | + |
| 123 | +This section covers how to: |
| 124 | + |
| 125 | +- Launch and use the WebUI |
| 126 | +- Use the command-line interface (CLI) for TTS |
| 127 | +- Use the Python API for programmatic access |
| 128 | +- Find example scripts and test resources |
| 129 | + |
| 130 | +## Step 6: Accessing Output Files from Android (Inside Debian) |
| 131 | + |
| 132 | +1. **Identify File Location:** Use `pwd` (e.g., `~/MeloTTS/`). |
| 133 | +2. **Copy Files to Shared Storage:** |
| 134 | + * Example: Copy `output.wav` to Downloads folder: |
| 135 | + ```bash |
| 136 | + # Adjust path if needed |
| 137 | + cp ./output.wav /sdcard/Download/output.wav |
| 138 | + ``` |
| 139 | +3. **Access on Android:** Use a File Manager app. |
| 140 | + |
| 141 | +## Step 7: Exiting and Re-entering (Inside Debian) |
| 142 | + |
| 143 | +1. **To fully exit:** `exit` at Termux prompt or close app. |
| 144 | +2. **To re-enter:** |
| 145 | + * Open Termux. |
| 146 | + * `proot-distro login debian` |
| 147 | + * `micromamba activate melotts` |
| 148 | + * `cd ~/MeloTTS` (if needed) |
| 149 | + * Run commands. |
| 150 | + * `micromamba deactivate`, `exit` when done. |
| 151 | + |
| 152 | +## Troubleshooting and Tips |
| 153 | + |
| 154 | +* **Check Environment Activation:** Always ensure `(melotts)` prefix is present. |
| 155 | +* **MeCab Issues:** If you see "RuntimeError: Could not configure working env. Have you installed MeCab?" during `pip install -e .` or runtime, this could be due to: |
| 156 | + - Missing system packages: Ensure `mecab`, `libmecab-dev`, and `mecab-ipadic-utf8` are properly installed via `apt`. |
| 157 | + - Python version mismatch: Make sure you created the Micromamba environment with Python 3.10 as specified in [Step 4](#step-4-create-micromamba-environment-and-install-melotts). |
| 158 | +* **Phantom Process Killing (Android 12+):** Android 12 and newer versions limit background processes, which can affect Termux. If you experience processes being killed unexpectedly: |
| 159 | + - **Using ADB from a PC (Recommended):** Connect your Android device to a PC with ADB installed and run: |
| 160 | + ```bash |
| 161 | + # Disable phantom process killing |
| 162 | + adb shell settings put global settings_enable_monitor_phantom_procs 0 |
| 163 | +
|
| 164 | + # Set max_phantom_processes to maximum value to permanently disable killing of phantom processes |
| 165 | + adb shell "/system/bin/device_config put activity_manager max_phantom_processes 2147483647" |
| 166 | + ``` |
| 167 | + - Alternatively, for Android 12+, you can disable phantom process killing by running these commands in Termux (not in Debian): |
| 168 | + ```bash |
| 169 | + # Disable phantom process killing |
| 170 | + settings put global settings_enable_monitor_phantom_procs 0 |
| 171 | + |
| 172 | + # Disable device config sync to prevent settings from being reset |
| 173 | + device_config set_sync_disabled_for_tests persistent |
| 174 | + |
| 175 | + # Verify settings |
| 176 | + settings get global settings_enable_monitor_phantom_procs |
| 177 | + device_config get_sync_disabled_for_tests |
| 178 | + ``` |
| 179 | + - These commands require either root access or ADB with proper permissions. |
| 180 | + - This is especially important for long-running processes or when multiple processes are spawned. |
| 181 | + - For more detailed instructions on disabling phantom process killing, refer to [this comprehensive guide](https://github.com/agnostic-apollo/Android-Docs/blob/master/en/docs/apps/processes/phantom-cached-and-empty-processes.md#commands-to-disable-phantom-process-killing-and-tldr). |
| 182 | +* **Performance/RAM:** Significant limitations remain on mobile devices. |
0 commit comments