mirror of
https://github.com/mudler/LocalAI.git
synced 2026-07-13 09:44:26 -04:00
C++/ggml transcription + speaker diarization + timestamps backend. Purego dlopens libmoss-transcribe.so (ggml statically linked) from moss-transcribe.cpp and serves offline AudioTranscription, parsing the [start][Sxx]text[end] output into segments with nanosecond timestamps. Adds the importer (surfaces in GET /backends/known), backend-matrix (Linux + Darwin/metal), backend/index.yaml, and a gallery entry (default q5_k GGUF from mudler/moss-transcribe.cpp-gguf). Local L0 smoke (go build + go test ./... = 16 pass, golangci-lint 0 issues) passed against the real libmoss-transcribe.so. The pre-commit coverage gate (full pkg/core + tests/e2e) could not run in the authoring sandbox (no live models, port 9090 held); CI must enforce it before merge. Assisted-by: Claude:claude-opus-4-8 golangci-lint Signed-off-by: Ettore Di Giacinto <mudler@localai.io> Co-authored-by: Ettore Di Giacinto <mudler@localai.io>
71 lines
2.1 KiB
Go
71 lines
2.1 KiB
Go
package main
|
|
|
|
// Started internally by LocalAI - one gRPC server per loaded model.
|
|
//
|
|
// Loads the moss-transcribe shared library via purego and registers the flat
|
|
// C-API entry points declared in moss_transcribe_capi.h. The library name can
|
|
// be overridden with MOSS_TRANSCRIBE_LIBRARY (mirrors the WHISPER_LIBRARY /
|
|
// PARAKEET_LIBRARY convention in the sibling backends); the default looks next
|
|
// to this binary for libmoss-transcribe.so on Linux and
|
|
// libmoss-transcribe.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("MOSS_TRANSCRIBE_LIBRARY")
|
|
if libName == "" {
|
|
if runtime.GOOS == "darwin" {
|
|
libName = "libmoss-transcribe.dylib"
|
|
} else {
|
|
libName = "libmoss-transcribe.so"
|
|
}
|
|
}
|
|
|
|
lib, err := purego.Dlopen(libName, purego.RTLD_NOW|purego.RTLD_GLOBAL)
|
|
if err != nil {
|
|
panic(fmt.Errorf("moss-transcribe-cpp: dlopen %q: %w", libName, err))
|
|
}
|
|
|
|
// Bound 1:1 to moss_transcribe_capi.h. The transcribe_* entry points return
|
|
// a malloc'd char* the caller owns; we register those as uintptr so we get
|
|
// the raw pointer back and can call moss_transcribe_capi_free_string on it
|
|
// (purego's string return would copy and forget the original pointer,
|
|
// leaking it on every call).
|
|
libFuncs := []LibFuncs{
|
|
{&CppAbiVersion, "moss_transcribe_capi_abi_version"},
|
|
{&CppLoad, "moss_transcribe_capi_load"},
|
|
{&CppFree, "moss_transcribe_capi_free"},
|
|
{&CppTranscribePath, "moss_transcribe_capi_transcribe_path"},
|
|
{&CppTranscribePcm, "moss_transcribe_capi_transcribe_pcm"},
|
|
{&CppFreeString, "moss_transcribe_capi_free_string"},
|
|
{&CppLastError, "moss_transcribe_capi_last_error"},
|
|
}
|
|
for _, lf := range libFuncs {
|
|
purego.RegisterLibFunc(lf.FuncPtr, lib, lf.Name)
|
|
}
|
|
|
|
fmt.Fprintf(os.Stderr, "[moss-transcribe-cpp] ABI=%d\n", CppAbiVersion())
|
|
|
|
flag.Parse()
|
|
|
|
if err := grpc.StartServer(*addr, &MossTranscribeCpp{}); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|