(request *schema.VADRequest, ctx context.Context, ml *model.ModelLoader, appConfig *config.ApplicationConfig, modelConfig config.ModelConfig)
| 10 | ) |
| 11 | |
| 12 | func VAD(request *schema.VADRequest, |
| 13 | ctx context.Context, |
| 14 | ml *model.ModelLoader, |
| 15 | appConfig *config.ApplicationConfig, |
| 16 | modelConfig config.ModelConfig) (*schema.VADResponse, error) { |
| 17 | // model.WithContext(ctx) overrides the app-context default set in |
| 18 | // ModelOptions so distributed routing decisions reach the request's |
| 19 | // X-LocalAI-Node holder via distributedhdr.Stamp. |
| 20 | opts := ModelOptions(modelConfig, appConfig, model.WithContext(ctx)) |
| 21 | vadModel, err := ml.Load(opts...) |
| 22 | if err != nil { |
| 23 | recordModelLoadFailure(appConfig, modelConfig.Name, modelConfig.Backend, err, nil) |
| 24 | return nil, err |
| 25 | } |
| 26 | |
| 27 | req := proto.VADRequest{ |
| 28 | Audio: request.Audio, |
| 29 | } |
| 30 | resp, err := vadModel.VAD(ctx, &req) |
| 31 | if err != nil { |
| 32 | return nil, err |
| 33 | } |
| 34 | |
| 35 | segments := []schema.VADSegment{} |
| 36 | for _, s := range resp.Segments { |
| 37 | segments = append(segments, schema.VADSegment{Start: s.Start, End: s.End}) |
| 38 | } |
| 39 | |
| 40 | return &schema.VADResponse{ |
| 41 | Segments: segments, |
| 42 | }, nil |
| 43 | } |
no test coverage detected