2023-07-14 23:19:43 +00:00
|
|
|
package localai
|
2023-06-22 15:53:10 +00:00
|
|
|
|
|
|
|
import (
|
2023-07-20 20:10:12 +00:00
|
|
|
"github.com/go-skynet/LocalAI/api/backend"
|
2023-07-14 23:19:43 +00:00
|
|
|
config "github.com/go-skynet/LocalAI/api/config"
|
|
|
|
|
|
|
|
"github.com/go-skynet/LocalAI/api/options"
|
2023-06-22 15:53:10 +00:00
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
type TTSRequest struct {
|
2023-08-07 20:41:07 +00:00
|
|
|
Model string `json:"model" yaml:"model"`
|
|
|
|
Input string `json:"input" yaml:"input"`
|
|
|
|
Backend string `json:"backend" yaml:"backend"`
|
2023-06-22 15:53:10 +00:00
|
|
|
}
|
|
|
|
|
2023-07-14 23:19:43 +00:00
|
|
|
func TTSEndpoint(cm *config.ConfigLoader, o *options.Option) func(c *fiber.Ctx) error {
|
2023-06-22 15:53:10 +00:00
|
|
|
return func(c *fiber.Ctx) error {
|
|
|
|
|
|
|
|
input := new(TTSRequest)
|
|
|
|
// Get input data from the request body
|
|
|
|
if err := c.BodyParser(input); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-08-07 20:41:07 +00:00
|
|
|
filePath, _, err := backend.ModelTTS(input.Backend, input.Input, input.Model, o.Loader, o)
|
2023-06-22 15:53:10 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return c.Download(filePath)
|
|
|
|
}
|
|
|
|
}
|