| package elevenlabs |
|
|
| import ( |
| "path/filepath" |
|
|
| "github.com/labstack/echo/v4" |
| "github.com/mudler/LocalAI/core/backend" |
| "github.com/mudler/LocalAI/core/config" |
| "github.com/mudler/LocalAI/core/http/middleware" |
| "github.com/mudler/LocalAI/core/schema" |
| "github.com/mudler/LocalAI/pkg/model" |
| "github.com/mudler/xlog" |
| ) |
|
|
| |
| |
| |
| |
| |
| func SoundGenerationEndpoint(cl *config.ModelConfigLoader, ml *model.ModelLoader, appConfig *config.ApplicationConfig) echo.HandlerFunc { |
| return func(c echo.Context) error { |
|
|
| input, ok := c.Get(middleware.CONTEXT_LOCALS_KEY_LOCALAI_REQUEST).(*schema.ElevenLabsSoundGenerationRequest) |
| if !ok || input.ModelID == "" { |
| return echo.ErrBadRequest |
| } |
|
|
| cfg, ok := c.Get(middleware.CONTEXT_LOCALS_KEY_MODEL_CONFIG).(*config.ModelConfig) |
| if !ok || cfg == nil { |
| return echo.ErrBadRequest |
| } |
|
|
| xlog.Debug("Sound Generation Request about to be sent to backend", "modelFile", "modelFile", "backend", cfg.Backend) |
|
|
| |
| filePath, _, err := backend.SoundGeneration(input.Text, input.Duration, input.Temperature, input.DoSample, nil, nil, ml, appConfig, *cfg) |
| if err != nil { |
| return err |
| } |
| return c.Attachment(filePath, filepath.Base(filePath)) |
|
|
| } |
| } |
|
|