Skip to content

IhorShevchuk/piper-objc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Piper‑ObjC Build

Swift implementation of the Piper speech synthesis engine. While the core is now written in Swift, it maintains full compatibility with Objective‑C.

Requirements

Platform Minimum
iOS 13.0
macOS 10.15

Installation

Swift Package Manager

dependencies: [
    .package(url: "https://github.com/IhorShevchuk/piper-objc.git", from: "0.2.15")
]

Two library products are available:

  • piper-objc — Core engine and low‑level Swift/Objective‑C API.
  • piper-player — High‑level Swift player built on AVFoundation.

Usage

Setup

import piper_player

let params = PiperPlayer.Params(
    modelPath: "/path/to/model.onnx",
    configPath: "/path/to/model.onnx.json",
    espeakNGData: "/path/to/espeak-ng-data"  // optional
)

let player = try PiperPlayer(params: params)

Play text

try await player.play(text: "Hello, world!")

Play SSML

try await player.play(ssml: "<speak>Hello</speak>")

// With a specific speaker (for multi-speaker models)
try await player.play(ssml: "<speak>Hello</speak>", speakerId: 1)

Synthesize to file

Returns the path to the generated .wav file, useful when you need custom playback (e.g. pitch shifting, speed control via AVAudioEngine).

// From plain text
if let path = await player.synthesizeToFile(text: "Hello, world!") {
    // use the .wav file at `path`
}

// From SSML
if let path = await player.synthesizeSSMLToFile(ssml: "<speak>Hello</speak>", speakerId: 0) {
    // use the .wav file at `path`
}

Stop playback

await player.stopAndCancel()

Low‑level Objective‑C API

#import <piper_objc/piper_objc.h>

Piper *piper = [[Piper alloc] initWithModelPath:@"model.onnx"
                                      configPath:@"model.onnx.json"
                                    espeakNGData:@""];

// Synthesize text to file
[piper synthesize:@"Hello" toFileAtPath:@"/tmp/out.wav" completion:^{
    // playback or processing
}];

// Synthesize SSML to file
[piper synthesizeSSML:@"<speak>Hello</speak>"
            speakerId:0
         toFileAtPath:@"/tmp/out.wav"
           completion:^{
    // playback or processing
}];

License

GPL-2.0

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages