flite
| Kind | ffi-c |
|---|---|
| Capabilities | ffi |
| Categories | audio ffi |
| Keywords | flite tts text-to-speech speech synthesis audio ffi |
Flite text-to-speech synthesis bindings for Kit
Files
| File | Description |
|---|---|
.editorconfig | Editor formatting configuration |
.gitignore | Git ignore rules for build artifacts and dependencies |
.tool-versions | asdf tool versions (Zig, Kit) |
LICENSE | MIT license file |
README.md | This file |
c/kit_flite.c | C FFI wrapper |
c/kit_flite.h | C header for FFI wrapper |
examples/hello.kit | Example: hello |
kit.toml | Package manifest with metadata and dependencies |
src/flite.kit | Flite text-to-speech synthesis bindings for Kit |
tests/flite.test.kit | Tests for flite |
tools/build-native.sh | Native Flite wrapper build script |
Dependencies
No Kit package dependencies.
This package links against the native Flite libraries:
libflitelibflite_usenglishlibflite_cmulexlibflite_cmu_us_kal
On macOS, Homebrew does not currently provide a flite formula. Install Flite with MacPorts:
sudo port install fliteAlternatively, 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 installOn Ubuntu:
sudo apt install flite1-devOn Fedora:
sudo dnf install flite-develInstallation
kit add gitlab.com/kit-lang/packages/kit-flite.gitUsage
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"
mainFor 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}"
mainDevelopment
Running Examples
Run examples with the interpreter:
kit run examples/hello.kit --allow=ffiCompile examples to a native binary:
kit build examples/hello.kit --allow=ffi && ./helloRunning Tests
Run the test suite:
kit testRun the test suite with coverage:
kit test --coverageRunning kit dev
Run the standard development workflow (format, check, and test):
kit devThis will:
- Format and check source files in
src/ - Run tests in
tests/with coverage
Running Parity
Run interpreter/compiler parity checks for examples:
kit parity --no-spinner --failures-onlyGenerating Documentation
Generate API documentation from doc comments:
kit docNote: Kit sources with doc comments (##) will generate HTML documents in docs/*.html
Cleaning Build Artifacts
Remove generated files, caches, and build artifacts:
kit task cleanNote: Defined in kit.toml.
Local Installation
To install this package locally for development:
kit installThis 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