Skip to main content

piper_phonemize 1.6.1 copy "piper_phonemize: ^1.6.1" to clipboard
piper_phonemize: ^1.6.1 copied to clipboard

Dart and Flutter bindings for piper-phonemize, a fast phonemization library backed by espeak-ng. Converts text to phoneme code points for use with text-to-speech systems.

piper-phonemize #

Try it Online #

You can try piper-phonemize directly in your browser using WebAssembly:

Introduction #

Phonemization library for Piper text-to-speech system.

Converts text to IPA phonemes using espeak-ng.

Supports Python, Go, Rust, Swift, Dart/Flutter, Pascal, JavaScript (Node.js/WASM), C/C++, Tauri, Android, and iOS.

Installation #

Python #

pip install piper_phonemize -f https://k2-fsa.github.io/icefall/piper_phonemize.html

Go #

go get github.com/csukuangfj/piper-phonemize-go/piper_phonemize

Rust #

Add to your Cargo.toml:

[dependencies]
piper-phonemize = "1.6.1"

The crate automatically downloads prebuilt libraries and embeds espeak-ng-data. No manual setup required.

Swift #

Add to your Package.swift:

dependencies: [
    .package(url: "https://github.com/csukuangfj/piper-phonemize", branch: "master")
]

JavaScript / Node.js #

WASM version (works everywhere, no native dependencies):

npm install piper-phonemize

Native addon (better performance, requires platform-specific binary, which is installed automagically):

npm install piper-phonemize-node

Flutter / Dart #

WASM-backed: works on Android, iOS, macOS, Linux, Windows, and Web. The espeak-ng-data is bundled inside the package (Flutter assets on native, embedded in the WASM bundle on web) — no extra downloads.

dependencies:
  piper_phonemize: ^1.6.1

Pre-built hello_world demo apps (macOS, iOS, Linux, Windows, Web) are released at the flutter tag.

C / C++ #

Download pre-built libraries from GitHub Releases or build from source.

Quick Start #

Python #

import piper_phonemize

# Initialize espeak-ng
piper_phonemize.initialize("/path/to/espeak-ng-data")

# Phonemize text
result = piper_phonemize.phonemize("Hello world", "en-us")
print(result)

Go #

package main

import (
    "fmt"
    pp "github.com/csukuangfj/piper-phonemize-go/piper_phonemize"
)

func main() {
    pp.Initialize("") // uses embedded espeak-ng-data
    result := pp.Phonemize("Hello world", "en-us")
    defer pp.DeletePhonemizeResult(result)
    for i := 0; i < result.GetNumSentences(); i++ {
        phonemes := result.GetPhonemes(i)
        fmt.Printf("Sentence %d: %v\n", i, phonemes)
    }
}

Rust #

use piper_phonemize::phonemize_to_string;

fn main() {
    // No initialization needed - espeak-ng-data is embedded
    let sentences = phonemize_to_string("Hello world", "en-us").unwrap();
    for s in &sentences {
        println!("{}", s);
    }
}

JavaScript / Node.js #

WASM version:

const piperPhonemize = require('piper-phonemize');

// espeak-ng-data is bundled — no initialization needed!
const result = piperPhonemize.phonemizeToString('Hello world', 'en-us');
console.log(result); // ['həlˈoʊ wˈɜːld']

Native addon:

const piperPhonemize = require('piper-phonemize-node');

// espeak-ng-data is bundled — no initialization needed!
const result = piperPhonemize.phonemizeToString('Hello world', 'en-us');
console.log(result); // ['həlˈoʊ wˈɜːld']

Flutter / Dart #

import 'package:piper_phonemize/piper_phonemize.dart' as piper;

void main() async {
  // Loads the WASM module on web, the native library elsewhere.
  await piper.initBindingsAsync();

  // On web the argument is ignored: espeak-ng-data is embedded in the WASM
  // bundle. On Flutter (non-web), use `await piper.extractEspeakNgData()`.
  piper.PiperPhonemize.initialize('');

  final phonemes = piper.PiperPhonemize.phonemize('Hello world', voice: 'en-us');
  print(phonemes); // [[104, 601, 108, 712, 111, 650, ...]] — code points
}

C #

#include "c-api.h"

int main() {
    PiperPhonemizeInitialize("/path/to/espeak-ng-data");

    PiperPhonemizeResult *result = PiperPhonemizeText("Hello world", "en-us");
    if (result) {
        int32_t num_sentences = PiperPhonemizeResultGetNumSentences(result);
        // Process phonemes...
        PiperPhonemizeDestroyResult(result);
    }
    return 0;
}

Tauri Example (Cross-Platform GUI) #

A cross-platform desktop/mobile app built with Tauri v2. See tauri-examples/ for details.

Pre-built apps are available on the GitHub Releases page:

Platform File
macOS (Apple Silicon) piper-phonemize-tauri-macos-arm64.app.zip
macOS (Intel) piper-phonemize-tauri-macos-x64.app.zip
Linux (x64) piper-phonemize-tauri-linux-x64.tar.bz2
Linux (arm64) piper-phonemize-tauri-linux-arm64.tar.bz2
Windows (x64) piper-phonemize-tauri-windows-x64.zip
Android (APK) app-universal-release-unsigned.apk

Building from Source #

Using CMake #

cmake -Bbuild -DBUILD_SHARED_LIBS=ON
cmake --build build --config Release

Using Docker #

docker buildx build . -t piper-phonemize --output 'type=local,dest=dist'

License #

GPL-3.0-or-later (due to espeak-ng dependency)

0
likes
150
points
3.95k
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Dart and Flutter bindings for piper-phonemize, a fast phonemization library backed by espeak-ng. Converts text to phoneme code points for use with text-to-speech systems.

Repository (GitHub)
View/report issues

License

GPL-3.0 (license)

Dependencies

ffi, flutter, path, path_provider

More

Packages that depend on piper_phonemize

Packages that implement piper_phonemize