Skip to main content

A Python front-end for the MBROLA speech synthesizer

Project description

pymbrola

GitHub Actions Workflow Status PyPI - Version PyPI - Python Version GitHub License PyPI - Status Docker Image Size (tag) GitHub Release


A Python interface for the MBROLA speech synthesizer, enabling programmatic creation of MBROLA-compatible phoneme files and automated audio synthesis. This module validates phoneme, duration, and pitch sequences, generates .pho files, and can call the MBROLA executable to synthesize speech audio from text-like inputs.

References: Dutoit, T., Pagel, V., Pierret, N., Bataille, F., & Van der Vrecken, O. (1996, October). The MBROLA project: Towards a set of high quality speech synthesizers free of use for non commercial purposes. In Proceeding of Fourth International Conference on Spoken Language Processing. ICSLP'96 (Vol. 3, pp. 1393-1396). IEEE. https://doi.org/10.1109/ICSLP.1996.607874

Features

  • Front-end to MBROLA: Easily create .pho files and synthesize audio with Python.
  • Input validation: Prevents invalid file and phoneme sequence errors.
  • Customizable: Easily set phonemes, durations, pitch contours, and leading/trailing silences.
  • Cross-platform (Linux/WSL): Automatically detects and adapts to Linux or Windows Subsystem for Linux environments.

Requirements

  • Python 3.10+
  • MBROLA binary installed and available in your system path, or via WSL for Windows users. To install MBROLA in your UBUNTU or WSL instance, run the [mbrola/install.sh] script:
sudo bin/install.sh --voice fr2 it4 # install voices fr2 and it4
sudo bin/install.sh --voice all # install all voices
sudo bin/install.sh # install no voices

A Docker image of Ubuntu 22.04 with a ready-to-go installation of MBROLA is available, for convenience.

  • MBROLA voices (e.g., it4) must be installed at /usr/share/mbrola/<voice>/<voice>.

Installation

MBROLA is currently available only on Linux-based systems like Ubuntu, or on Windows via the Windows Susbsystem for Linux (WSL). Install MBROLA in your machine following the instructions in the MBROLA repository. If you are using WSL, install MBROLA in WSL. After this, you should be ready to install pymbrola using pip.

pip install mbrola

Usage

Synthesize a Word

import mbrola

# Create an MBROLA object
caffe = MBROLA(
    word="caffè",
    phon=["k", "a", "f", "f", "E1"],
    durations=100,  # or [100, 120, 100, 110]
    pitch=[100, [200, 50, 200], 100, 100, 200]
)

# Display phoneme sequence
print(caffe)

# Export PHO file
caffe.export_pho("caffe.pho")

# Synthesize and save audio (WAV file)
caffe.make_sound("caffe.wav", voice="it4")

The module uses the MBROLA command line tool under the hood. Ensure MBROLA is installed and available in your system path, or WSL if on Windows.

Specifying the pitch contour

pymbrola implements the piecewise linear pitch specification as different inputs:

If pitch is specified as an integer, pitch is assumed constant across phonemes:

phon = list("kasa")
pitch = 200
validate_pitch(200, phon)
# [[(0, 200)], [(0, 200)], [(0, 200)], [(0, 200)]]

If pitch is specified as a list, each element in mapped to each phoneme. Integers in the list are treated as before (constant pitch for the whole phoneme):

phon = list("kasa")
pitch = [200, 50, 50, 100]
validate_pitch(pitch, phon)
# [[(0, 200)], [(0, 50)], [(0, 50)], [(0, 100)]]

Empty lists inside the main list are treated as constant pitch sections:

phon = list("kasa")
pitch = [[], 50, [], 100]
validate_pitch(pitch, phon)
# [[], [(0, 50)], [], [(0, 100)]]

Non-empty lists must consist in lists of tuples. Each tuple contains two values. The first value is the time (as a percentage of the duration of the phoneme) at which the pitch should be modified inside the phoneme (as a float or integer), and the second value is the pitch that should be set at that time (as an integer):

phon = list("kasa")
pitch = [[], [(25, 50), (50, 100), (75, 150), (90, 200)], [], 100]
validate_pitch(pitch, phon)
# [[], [(25, 50), (50, 100), (75, 150), (90, 200)], [], [(0, 100)]]

Docker image

For convenience, a Docker image is available at Dockerhub:

docker run -it gongcastro/pymbrola:latest

Troubleshooting

  • Ensure MBROLA and the required voices are installed and available at /usr/share/mbrola/<voice>/<voice>.
  • If you encounter an error about platform support, make sure you are running on Linux or WSL.
  • Write an issue, I'll look into it ASAP.

License

pymbrola is distributed under the terms of the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mbrola-0.3.2.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mbrola-0.3.2-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file mbrola-0.3.2.tar.gz.

File metadata

  • Download URL: mbrola-0.3.2.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mbrola-0.3.2.tar.gz
Algorithm Hash digest
SHA256 018a0fcf5e459aee20d0b6e2ad1dc6f6f7e3af71cf5ed9a2f49a0cd86d495278
MD5 dcd8418effa54bf7b81b43631f465262
BLAKE2b-256 f2333a57e820445b22917a57fb17aef91b6f0fc35b5aca222d19e019a9acae80

See more details on using hashes here.

File details

Details for the file mbrola-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: mbrola-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mbrola-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 57254c2db0c5556c2a3c38ee071f94136a317225c1575fcf186037b148a0adcd
MD5 8d1324a3b0d95803d2ae61fc1e283188
BLAKE2b-256 fa95942d8489d1bcc65d70e65e5967d8479b202740865b2a6c721130e3202a1a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page