mirror of
https://github.com/mudler/LocalAI.git
synced 2026-10-10 07:47:29 -04:00
* feat(parakeet-cpp): load bundle GGUF files and use their components by role A bundle GGUF holds several models (ASR, VAD, diarization, sound events, speaker encoder) in one file, each with its own licence. Detect a bundle at load through parakeet_capi_bundle_components_json and open components with parakeet_capi_load_component. The three symbols are probed together, so an older libparakeet.so still loads plain files as before. The only ASR component is the primary model; bundle_asr:<name> picks one when there are several. A Silero VAD component of the primary bundle is loaded without an option and serves /v1/vad and vad:true. The diar, ced and voice components load on request: diar_component, sound_component and speaker_component, or a companion option (diarization_model, sound_model, speaker_model, vad_model) that names a bundle, even the model file itself. vad_component picks a VAD component and implies vad:true. A role the bundle cannot fill fails the load with the component list, and a diarization or sound request on a model without that role names the bundle components. Every existing option and single-file model behaves as before. Assisted-by: Claude:claude-sonnet-5-5 [Claude Code] * chore(parakeet-cpp): bump parakeet.cpp to 781a973 Brings in the bundle GGUF format and its C-API (parakeet_capi_load_component, parakeet_capi_bundle_components_json, parakeet_capi_load_error). Assisted-by: Claude:claude-sonnet-5-5 [Claude Code] * feat(parakeet-cpp): gallery entries for the bundle GGUF files, docs Add parakeet-cpp-bundle-small (338 MB: Parakeet TDT+CTC 110M, Nemotron-3- Diarization, CED-Small, WeSpeaker ResNet34-LM, Silero VAD), -standard (1.1 GB, Parakeet TDT 0.6B v3 instead of the 110M model) and -moondream-redux (215 MB: packed Redux and Silero VAD, CPU only). One install serves transcription, VAD, diarization, sound events and speaker naming through the component options. The existing single-purpose entries stay. A bundle has no single licence, so the entries use license: other and state the licence and credit of each component in the description, with the upstream inconsistency of the CED licence. The docs get a section on bundles in audio-to-text with the entries, the roles, the options and the licence notice, and pointers from the VAD, diarization and sound classification pages. A gallery test checks the file names, checksums, usecases and options. Assisted-by: Claude:claude-sonnet-5-5 [Claude Code] --------- Co-authored-by: Ettore Di Giacinto <mudler@localai.io>
183 lines
9.1 KiB
Go
183 lines
9.1 KiB
Go
package main
|
|
|
|
// Started internally by LocalAI - one gRPC server per loaded model.
|
|
//
|
|
// Loads the parakeet shared library via purego and registers the flat
|
|
// C-API entry points declared in parakeet_capi.h. The library name can be
|
|
// overridden with PARAKEET_LIBRARY (mirrors the WHISPER_LIBRARY /
|
|
// VIBEVOICECPP_LIBRARY convention in the sibling backends); the default
|
|
// looks next to this binary for libparakeet.so on Linux and
|
|
// libparakeet.dylib on macOS.
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
"runtime"
|
|
|
|
"github.com/ebitengine/purego"
|
|
grpc "github.com/mudler/LocalAI/pkg/grpc"
|
|
)
|
|
|
|
var (
|
|
addr = flag.String("addr", "localhost:50051", "the address to connect to")
|
|
)
|
|
|
|
type LibFuncs struct {
|
|
FuncPtr any
|
|
Name string
|
|
}
|
|
|
|
func main() {
|
|
libName := os.Getenv("PARAKEET_LIBRARY")
|
|
if libName == "" {
|
|
if runtime.GOOS == "darwin" {
|
|
libName = "libparakeet.dylib"
|
|
} else {
|
|
libName = "libparakeet.so"
|
|
}
|
|
}
|
|
|
|
lib, err := purego.Dlopen(libName, purego.RTLD_NOW|purego.RTLD_GLOBAL)
|
|
if err != nil {
|
|
panic(fmt.Errorf("parakeet-cpp: dlopen %q: %w", libName, err))
|
|
}
|
|
|
|
// Bound 1:1 to parakeet_capi.h. The C-API returns malloc'd char*
|
|
// buffers from transcribe_*; we register those as uintptr so we get
|
|
// the raw pointer back and can call parakeet_capi_free_string on it
|
|
// (purego's string return would copy and forget the original pointer,
|
|
// leaking it on every call).
|
|
libFuncs := []LibFuncs{
|
|
{&CppAbiVersion, "parakeet_capi_abi_version"},
|
|
{&CppLoad, "parakeet_capi_load"},
|
|
{&CppFree, "parakeet_capi_free"},
|
|
{&CppTranscribePath, "parakeet_capi_transcribe_path"},
|
|
{&CppTranscribePathJSON, "parakeet_capi_transcribe_path_json"},
|
|
{&CppStreamBegin, "parakeet_capi_stream_begin"},
|
|
{&CppStreamFeed, "parakeet_capi_stream_feed"},
|
|
{&CppStreamFinalize, "parakeet_capi_stream_finalize"},
|
|
{&CppStreamFree, "parakeet_capi_stream_free"},
|
|
{&CppFreeString, "parakeet_capi_free_string"},
|
|
{&CppLastError, "parakeet_capi_last_error"},
|
|
}
|
|
for _, lf := range libFuncs {
|
|
purego.RegisterLibFunc(lf.FuncPtr, lib, lf.Name)
|
|
}
|
|
|
|
// The batched-JSON entry point exists only in newer libparakeet.so (ABI >= 2).
|
|
// Probe with Dlsym and register only if present, so the backend still loads
|
|
// against an older library (it falls back to per-request transcription).
|
|
if sym, err := purego.Dlsym(lib, "parakeet_capi_transcribe_pcm_batch_json"); err == nil && sym != 0 {
|
|
purego.RegisterLibFunc(&CppTranscribePcmBatchJSON, lib, "parakeet_capi_transcribe_pcm_batch_json")
|
|
}
|
|
|
|
// VAD-segmented offline transcription (vad:true model option). Additive in
|
|
// the C-API (no ABI bump); same probe pattern, so an older libparakeet.so
|
|
// still loads and Load refuses vad:true with a clear message.
|
|
if sym, err := purego.Dlsym(lib, "parakeet_capi_transcribe_path_json_vad"); err == nil && sym != 0 {
|
|
purego.RegisterLibFunc(&CppTranscribePathJSONVad, lib, "parakeet_capi_transcribe_path_json_vad")
|
|
}
|
|
|
|
// Silero VAD, the standalone VAD RPC and transcription with an external Silero
|
|
// (vad_model: option). Additive in the C-API (no ABI bump). Each symbol is
|
|
// probed on its own: a library without one still loads, and the feature that
|
|
// needs it fails with a clear message only when it is used.
|
|
if sym, err := purego.Dlsym(lib, "parakeet_capi_transcribe_path_json_vad_with"); err == nil && sym != 0 {
|
|
purego.RegisterLibFunc(&CppTranscribePathJSONVadWith, lib, "parakeet_capi_transcribe_path_json_vad_with")
|
|
}
|
|
if sym, err := purego.Dlsym(lib, "parakeet_capi_vad_pcm_json"); err == nil && sym != 0 {
|
|
purego.RegisterLibFunc(&CppVadPcmJSON, lib, "parakeet_capi_vad_pcm_json")
|
|
}
|
|
|
|
// Bundle GGUF (one file with several models; docs/bundle.md in parakeet.cpp).
|
|
// Additive in the C-API. The three entry points come together, so one probe
|
|
// decides; without them a bundle file is handled like any other file.
|
|
if sym, err := purego.Dlsym(lib, "parakeet_capi_load_component"); err == nil && sym != 0 {
|
|
if sym2, err2 := purego.Dlsym(lib, "parakeet_capi_bundle_components_json"); err2 == nil && sym2 != 0 {
|
|
if sym3, err3 := purego.Dlsym(lib, "parakeet_capi_load_error"); err3 == nil && sym3 != 0 {
|
|
purego.RegisterLibFunc(&CppLoadComponent, lib, "parakeet_capi_load_component")
|
|
purego.RegisterLibFunc(&CppBundleComponentsJSON, lib, "parakeet_capi_bundle_components_json")
|
|
purego.RegisterLibFunc(&CppLoadError, lib, "parakeet_capi_load_error")
|
|
}
|
|
}
|
|
}
|
|
|
|
// Per-request language variants (multilingual nemotron). Same probe pattern:
|
|
// present only in libparakeet.so built with multilingual support, so the
|
|
// backend still loads against an older library and falls back to the
|
|
// non-lang batched + streaming entry points (model default / "auto").
|
|
if sym, err := purego.Dlsym(lib, "parakeet_capi_transcribe_pcm_batch_json_lang"); err == nil && sym != 0 {
|
|
purego.RegisterLibFunc(&CppTranscribePcmBatchJSONLang, lib, "parakeet_capi_transcribe_pcm_batch_json_lang")
|
|
}
|
|
if sym, err := purego.Dlsym(lib, "parakeet_capi_stream_begin_lang"); err == nil && sym != 0 {
|
|
purego.RegisterLibFunc(&CppStreamBeginLang, lib, "parakeet_capi_stream_begin_lang")
|
|
}
|
|
|
|
// Streaming JSON entry points (ABI v4): surface per-word timestamps on the
|
|
// streaming path. Same probe pattern; absent in older libparakeet.so, where
|
|
// the backend falls back to the text-only streaming feed.
|
|
if sym, err := purego.Dlsym(lib, "parakeet_capi_stream_feed_json"); err == nil && sym != 0 {
|
|
purego.RegisterLibFunc(&CppStreamFeedJSON, lib, "parakeet_capi_stream_feed_json")
|
|
purego.RegisterLibFunc(&CppStreamFinalizeJSON, lib, "parakeet_capi_stream_finalize_json")
|
|
}
|
|
|
|
// Model roles + diarization/sound (ABI v7-v8): parakeet_capi_model_kind is
|
|
// what lets Load tell an ASR/diarization/sound context apart, so it gates
|
|
// every other new symbol below (an older libparakeet.so gets none of
|
|
// them, and companion model options are rejected in roles.go). Diarization
|
|
// itself (diarize_pcm, transcribe_and_diarize_json) predates model_kind
|
|
// (ABI v7), so it is probed on its own.
|
|
if sym, err := purego.Dlsym(lib, "parakeet_capi_diarize_pcm"); err == nil && sym != 0 {
|
|
purego.RegisterLibFunc(&CppDiarizePCM, lib, "parakeet_capi_diarize_pcm")
|
|
}
|
|
if sym, err := purego.Dlsym(lib, "parakeet_capi_transcribe_and_diarize_json"); err == nil && sym != 0 {
|
|
purego.RegisterLibFunc(&CppTranscribeAndDiarizeJSON, lib, "parakeet_capi_transcribe_and_diarize_json")
|
|
}
|
|
if sym, err := purego.Dlsym(lib, "parakeet_capi_model_kind"); err == nil && sym != 0 {
|
|
purego.RegisterLibFunc(&CppModelKind, lib, "parakeet_capi_model_kind")
|
|
purego.RegisterLibFunc(&CppNumClasses, lib, "parakeet_capi_num_classes")
|
|
purego.RegisterLibFunc(&CppSoundOptsDefault, lib, "parakeet_capi_sound_opts_default")
|
|
purego.RegisterLibFunc(&CppSoundStreamBegin, lib, "parakeet_capi_sound_stream_begin")
|
|
purego.RegisterLibFunc(&CppSoundStreamFeed, lib, "parakeet_capi_sound_stream_feed")
|
|
purego.RegisterLibFunc(&CppSoundStreamDrainScoresJSON, lib, "parakeet_capi_sound_stream_drain_scores_json")
|
|
purego.RegisterLibFunc(&CppFreeSoundSegments, lib, "parakeet_capi_free_sound_segments")
|
|
purego.RegisterLibFunc(&CppSoundStreamFree, lib, "parakeet_capi_sound_stream_free")
|
|
purego.RegisterLibFunc(&CppSceneOptsDefault, lib, "parakeet_capi_scene_opts_default")
|
|
purego.RegisterLibFunc(&CppSceneStreamBegin, lib, "parakeet_capi_scene_stream_begin")
|
|
purego.RegisterLibFunc(&CppSceneStreamFeedJSON, lib, "parakeet_capi_scene_stream_feed_json")
|
|
purego.RegisterLibFunc(&CppSceneStreamLastError, lib, "parakeet_capi_scene_stream_last_error")
|
|
purego.RegisterLibFunc(&CppSceneStreamFree, lib, "parakeet_capi_scene_stream_free")
|
|
}
|
|
// Speaker identification (ABI v9 and v10). Probed separately from model_kind so an older
|
|
// libparakeet.so still loads; speaker_model: is refused in roles.go unless the v10 symbols exist.
|
|
if sym, err := purego.Dlsym(lib, "parakeet_capi_scene_stream_begin_speaker"); err == nil && sym != 0 {
|
|
purego.RegisterLibFunc(&CppSpeakerDim, lib, "parakeet_capi_speaker_dim")
|
|
purego.RegisterLibFunc(&CppSpeakerRegistryNew, lib, "parakeet_capi_speaker_registry_new")
|
|
purego.RegisterLibFunc(&CppSpeakerRegistryFree, lib, "parakeet_capi_speaker_registry_free")
|
|
purego.RegisterLibFunc(&CppSpeakerRegistryLastError, lib, "parakeet_capi_speaker_registry_last_error")
|
|
purego.RegisterLibFunc(&CppSceneStreamBeginSpeaker, lib, "parakeet_capi_scene_stream_begin_speaker")
|
|
purego.RegisterLibFunc(&CppTranscribeAndDiarizeNamedJSON, lib, "parakeet_capi_transcribe_and_diarize_named_json")
|
|
}
|
|
if sym, err := purego.Dlsym(lib, "parakeet_capi_diarize_named_pcm_json"); err == nil && sym != 0 {
|
|
purego.RegisterLibFunc(&CppSpeakerRegistryAddEmbedding, lib, "parakeet_capi_speaker_registry_add_embedding")
|
|
purego.RegisterLibFunc(&CppDiarizeNamedPCMJSON, lib, "parakeet_capi_diarize_named_pcm_json")
|
|
}
|
|
|
|
for _, lf := range []LibFuncs{
|
|
{&CppSpeakerIdentity, "parakeet_capi_speaker_identity"},
|
|
{&CppSpeakerDim, "parakeet_capi_speaker_dim"},
|
|
{&CppDiarizeProfilesPCMJSON, "parakeet_capi_diarize_profiles_pcm_json"},
|
|
} {
|
|
if sym, err := purego.Dlsym(lib, lf.Name); err == nil && sym != 0 {
|
|
purego.RegisterLibFunc(lf.FuncPtr, lib, lf.Name)
|
|
}
|
|
}
|
|
fmt.Fprintf(os.Stderr, "[parakeet-cpp] ABI=%d\n", CppAbiVersion())
|
|
|
|
flag.Parse()
|
|
|
|
if err := grpc.StartServer(*addr, &ParakeetCpp{}); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|