mirror of
https://github.com/mudler/LocalAI.git
synced 2026-10-05 04:24:39 -04:00
* feat(parakeet-cpp): implement the VAD call and add the vad_model option The backend now serves the VAD gRPC call (POST /vad and /v1/vad) with the standalone VAD of libparakeet. It accepts a Silero VAD GGUF as the model file, or an ASR model with a VAD head (Moondream Ultra and Redux). The request audio is float32 PCM at 16 kHz; the response lists the speech segments in seconds, like the silero-vad backend. A model with neither fails the request with the library message. The vad_threshold, vad_min_pause, vad_min_speech, vad_speech_pad and vad_max_segment options tune the segmenter. Unset values keep the defaults of the detector in use, and a bad value fails the load. The vad_model option names a Silero GGUF, resolved against the models directory like the other companion files. It lets any ASR model cut long audio at pauses through parakeet_capi_transcribe_path_json_vad_with, and it implies vad. vad:true alone still uses the model's own head. The new symbols are probed like the existing optional ones. A library without them still loads; the feature that needs one fails with a clear message only when it is used. Assisted-by: Claude:claude-sonnet-5-5 [go test] * feat(gallery): add parakeet-cpp VAD entries and a v3 plus Silero example Add VAD-only entries for the parakeet-cpp backend: the VAD heads of Moondream Redux (packed, CPU) and Ultra (Q8_0), which share their files with the existing ASR entries, and Silero VAD v6.2.3 as a GGUF (MIT, Silero Team). The parakeet-cpp-vad entry installs Silero; it has no variants, because variant ranking prefers the larger build that fits and these are different detectors. Add parakeet-cpp-tdt-0.6b-v3-silero-vad, a v3 entry that sets vad_model so long audio is cut at pauses by Silero. The Silero GGUF entries point at the intended Hugging Face URL of the file; the existing silero-vad entries are unchanged. A test checks the usecases, the shared files and the default entry and the vad_model reference. Assisted-by: Claude:claude-sonnet-5-5 [go test] * docs: describe parakeet-cpp VAD and the vad_model option Document the VAD endpoint on the parakeet-cpp backend (Silero GGUF and the VAD heads of Moondream Ultra and Redux), the vad_* tuning options, and the vad_model option that lets an ASR model without a VAD head cut long audio with Silero. Assisted-by: Claude:claude-sonnet-5-5 * chore(parakeet-cpp): bump parakeet.cpp to 6165e3d Pin the release that adds the standalone VAD (Ultra/Redux head and Silero) and the C API calls the backend now uses. Assisted-by: Claude:claude-sonnet-5-5 --------- Co-authored-by: Ettore Di Giacinto <mudler@localai.io>
170 lines
8.3 KiB
Go
170 lines
8.3 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")
|
|
}
|
|
|
|
// 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)
|
|
}
|
|
}
|