Files
LocalAI/backend/go/omnivoice-cpp/request_controls.go
T
mudler-agentandEttore Di Giacinto 440225a724 feat(omnivoice): add bounded duration controls (#12637)
* test(omnivoice): expose ignored duration controls

Compile the real wrapper with a model-free engine fixture. Four failing
assertions expose ignored duration, postprocessing, and validation.

Assisted-by: nib:gpt-6-astra
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>

* feat(omnivoice): add bounded duration controls

Validate request controls before reference reads or native output.
Preserve engine defaults when controls are omitted. Bound forced
single-shot duration to 30 seconds as wrapper resource policy.

Exercise the real native boundary, streaming rejection, and defaults
with synthetic PCM. Document quantization and postprocessing limits.

Assisted-by: nib:gpt-6-astra
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>

* test(omnivoice): require fixture-free ordinary tests

Expose the ordinary suite regression before isolating native fixtures.
Require selected native tests to reject a missing fixture explicitly.

Assisted-by: nib:gpt-6-astra
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>

* fix(omnivoice): isolate native fixture tests

Ordinary Go tests must run without a compiled native fixture.
Select fixture specs explicitly in the dedicated gate while keeping
parser tests ordinary and native checks mandatory.

Assisted-by: nib:gpt-6-astra
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>

---------

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Co-authored-by: Ettore Di Giacinto <mudler@localai.io>
2026-10-11 23:08:01 +02:00

45 lines
1.4 KiB
Go

// SPDX-License-Identifier: MIT
package main
import (
"fmt"
"math"
"strconv"
)
type requestControls struct {
durationFrames int32
postprocess int32
}
func parseRequestControls(params map[string]string, streaming bool) (requestControls, error) {
controls := requestControls{postprocess: -1}
if value, present := params["duration"]; present {
seconds, err := strconv.ParseFloat(value, 64)
// Forced duration bypasses chunking. This cap is wrapper resource policy,
// not an engine positional limit or an allocation/success guarantee.
if err != nil || math.IsNaN(seconds) || math.IsInf(seconds, 0) || seconds <= 0 || seconds > 30 {
return controls, fmt.Errorf("omnivoice: duration must be finite seconds greater than 0 and at most 30")
}
frames := math.Max(1, math.Floor(seconds*25)) // bundled codec: 24000 / 960
if frames < 1 || frames > 750 {
return controls, fmt.Errorf("omnivoice: duration frame count out of range")
}
controls.durationFrames = int32(frames)
}
if value, present := params["postprocess"]; present {
switch value {
case "true":
controls.postprocess = 1
case "false":
controls.postprocess = 0
default:
return controls, fmt.Errorf("omnivoice: postprocess must be exactly true or false")
}
}
if streaming && controls.postprocess == 0 {
return controls, fmt.Errorf("omnivoice: streaming does not support postprocess=false")
}
return controls, nil
}