mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-02 08:43:10 +00:00
* squash past, centralize request middleware PR Signed-off-by: Dave Lee <dave@gray101.com> * migrate bruno request files to examples repo Signed-off-by: Dave Lee <dave@gray101.com> * fix Signed-off-by: Dave Lee <dave@gray101.com> * Update tests/e2e-aio/e2e_test.go Signed-off-by: Ettore Di Giacinto <mudler@users.noreply.github.com> --------- Signed-off-by: Dave Lee <dave@gray101.com> Signed-off-by: Ettore Di Giacinto <mudler@users.noreply.github.com> Co-authored-by: Ettore Di Giacinto <mudler@users.noreply.github.com>
44 lines
1.4 KiB
Go
44 lines
1.4 KiB
Go
package elevenlabs
|
|
|
|
import (
|
|
"github.com/mudler/LocalAI/core/backend"
|
|
"github.com/mudler/LocalAI/core/config"
|
|
"github.com/mudler/LocalAI/core/http/middleware"
|
|
"github.com/mudler/LocalAI/pkg/model"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
"github.com/mudler/LocalAI/core/schema"
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
// TTSEndpoint is the OpenAI Speech API endpoint https://platform.openai.com/docs/api-reference/audio/createSpeech
|
|
// @Summary Generates audio from the input text.
|
|
// @Param voice-id path string true "Account ID"
|
|
// @Param request body schema.TTSRequest true "query params"
|
|
// @Success 200 {string} binary "Response"
|
|
// @Router /v1/text-to-speech/{voice-id} [post]
|
|
func TTSEndpoint(cl *config.BackendConfigLoader, ml *model.ModelLoader, appConfig *config.ApplicationConfig) func(c *fiber.Ctx) error {
|
|
return func(c *fiber.Ctx) error {
|
|
|
|
voiceID := c.Params("voice-id")
|
|
|
|
input, ok := c.Locals(middleware.CONTEXT_LOCALS_KEY_LOCALAI_REQUEST).(*schema.ElevenLabsTTSRequest)
|
|
if !ok || input.ModelID == "" {
|
|
return fiber.ErrBadRequest
|
|
}
|
|
|
|
cfg, ok := c.Locals(middleware.CONTEXT_LOCALS_KEY_MODEL_CONFIG).(*config.BackendConfig)
|
|
if !ok || cfg == nil {
|
|
return fiber.ErrBadRequest
|
|
}
|
|
|
|
log.Debug().Str("modelName", input.ModelID).Msg("elevenlabs TTS request recieved")
|
|
|
|
filePath, _, err := backend.ModelTTS(input.Text, voiceID, input.LanguageCode, ml, appConfig, *cfg)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return c.Download(filePath)
|
|
}
|
|
}
|