flite

Flite text-to-speech synthesis bindings for Kit

Files

FileDescription
.editorconfigEditor formatting configuration
.gitignoreGit ignore rules for build artifacts and dependencies
.tool-versionsasdf tool versions (Zig, Kit)
LICENSEMIT license file
README.mdThis file
c/kit_flite.cC FFI wrapper
c/kit_flite.hC header for FFI wrapper
examples/hello.kitExample: hello
kit.tomlPackage manifest with metadata and dependencies
src/flite.kitFlite text-to-speech synthesis bindings for Kit
tests/flite.test.kitTests for flite
tools/build-native.shNative Flite wrapper build script

Dependencies

No Kit package dependencies.

This package links against the native Flite libraries:

  • libflite
  • libflite_usenglish
  • libflite_cmulex
  • libflite_cmu_us_kal

On macOS, Homebrew does not currently provide a flite formula. Install Flite with MacPorts:

sudo port install flite

Alternatively, build festvox/flite from source into /usr/local or /opt/homebrew.

For non-standard prefixes, pass the prefix when installing:

KIT_FLITE_PREFIX=/path/to/flite/prefix kit install

On Ubuntu:

sudo apt install flite1-dev

On Fedora:

sudo dnf install flite-devel

Installation

kit add gitlab.com/kit-lang/packages/kit-flite.git

Usage

import Kit.Flite as Flite

main = fn =>
  # Select the bundled kal voice
  match Flite.select-voice "kal"
    | Err e -> println "Voice selection failed: ${e}"
    | Ok voice ->
      # Synthesize text to a wave handle
      match Flite.synthesize "Hello from Kit and Flite." voice
        | Err e -> println "Synthesis failed: ${e}"
        | Ok wave ->
          # Inspect wave metadata
          println "Voice: ${Flite.voice-name voice}"
          println "Sample rate: ${Flite.sample-rate wave} Hz"
          println "Duration: ${Flite.wave-duration wave} seconds"

          # Save a WAV file and release the wave
          Flite.save-wave wave "/tmp/flite-hello.wav"
          Flite.free-wave wave
          println "Saved to /tmp/flite-hello.wav"

main

For the shortest path, use the convenience function:

import Kit.Flite as Flite

main = fn =>
  match Flite.quick-speak "Hello, world!" "/tmp/hello.wav"
    | Ok _ -> println "Saved to /tmp/hello.wav"
    | Err e -> println "Error: ${e}"

main

Development

Running Examples

Run examples with the interpreter:

kit run examples/hello.kit --allow=ffi

Compile examples to a native binary:

kit build examples/hello.kit --allow=ffi && ./hello

Running Tests

Run the test suite:

kit test

Run the test suite with coverage:

kit test --coverage

Running kit dev

Run the standard development workflow (format, check, and test):

kit dev

This will:

  1. Format and check source files in src/
  2. Run tests in tests/ with coverage

Running Parity

Run interpreter/compiler parity checks for examples:

kit parity --no-spinner --failures-only

Generating Documentation

Generate API documentation from doc comments:

kit doc

Note: Kit sources with doc comments (##) will generate HTML documents in docs/*.html

Cleaning Build Artifacts

Remove generated files, caches, and build artifacts:

kit task clean

Note: Defined in kit.toml.

Local Installation

To install this package locally for development:

kit install

This installs the package to ~/.kit/packages/@kit/flite/, builds the native libkit_flite wrapper, and makes it available for import as Kit.Flite in other projects.

License

This package is released under the MIT License - see LICENSE for details.

Flite is released under a BSD-style license.

Exported Functions & Types

FliteError

Errors that can occur during Flite operations.

Variants

FliteInitError {message}
FliteVoiceError {message}
FliteSynthesisError {message}
FliteWaveError {message}

init

Initialize Flite (idempotent, automatically called by other functions)

Result () FliteError

select-voice

Select a voice by name Common voices: "kal", "kal16", "awb", "rms", "slt"

NonEmptyString -> Result Ptr FliteError

load-voice

Load a voice from a .flitevox file

NonEmptyString -> Result Ptr FliteError

voice-name

Get the name of a voice

Ptr -> String

synthesize

Synthesize text to a wave

NonEmptyString -> Ptr -> Result Ptr FliteError

synthesize-to-file

Synthesize text directly to a file Returns duration in seconds

NonEmptyString -> Ptr -> NonEmptyString -> Result Float FliteError

sample-rate

Get wave sample rate in Hz

Ptr -> Int

num-samples

Get number of samples in wave

Ptr -> Int

num-channels

Get number of channels in wave

Ptr -> Int

wave-duration

Get wave duration in seconds

Ptr -> Float

save-wave

Save wave to a WAV file

Ptr -> NonEmptyString -> Result () FliteError

save-wave-as

Save wave to file with specified type ("riff", "raw", "snd")

Ptr -> NonEmptyString -> NonEmptyString -> Result () FliteError

resample

Resample wave to a new sample rate

Ptr -> PositiveInt -> Unit

rescale

Rescale wave amplitude (factor is percentage, e.g., 50 for half volume)

Ptr -> Int -> Unit

free-wave

Free wave memory (must be called when done with wave)

Ptr -> Unit

set-pitch

Set voice pitch (F0 target mean, default around 110-180 Hz depending on voice)

Ptr -> PositiveFloat -> Unit

set-speed

Set voice speed (duration stretch, 1.0 is normal, higher is slower)

Ptr -> PositiveFloat -> Unit

set-feature-float

Set a float feature on a voice

Ptr -> NonEmptyString -> Float -> Unit

set-feature-int

Set an int feature on a voice

Ptr -> NonEmptyString -> Int -> Unit

set-feature-string

Set a string feature on a voice

Ptr -> NonEmptyString -> String -> Unit

get-feature-float

Get a float feature from a voice

Ptr -> NonEmptyString -> Float -> Float

get-feature-int

Get an int feature from a voice

Ptr -> NonEmptyString -> Int -> Int

get-feature-string

Get a string feature from a voice

Ptr -> NonEmptyString -> String -> String

speak-to-file

Synthesize text and save directly to a WAV file Combines select-voice, synthesize, save-wave, and free-wave

NonEmptyString -> NonEmptyString -> NonEmptyString -> Result () FliteError

quick-speak

Quick synthesis using default voice (kal)

NonEmptyString -> NonEmptyString -> Result () FliteError