feat(audio): set audio content type (#8416)

* feat(audio): set audio content type

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>

* chore: add tests

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>

---------

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
Ettore Di Giacinto
2026-02-05 19:14:12 +01:00
committed by GitHub
parent 218d0526cb
commit 697f6aa71c
8 changed files with 179 additions and 20 deletions

View File

@@ -8,6 +8,7 @@ import (
"github.com/mudler/LocalAI/core/config"
"github.com/mudler/LocalAI/core/http/middleware"
"github.com/mudler/LocalAI/core/schema"
"github.com/mudler/LocalAI/pkg/audio"
"github.com/mudler/LocalAI/pkg/model"
"github.com/mudler/xlog"
)
@@ -51,7 +52,11 @@ func SoundGenerationEndpoint(cl *config.ModelConfigLoader, ml *model.ModelLoader
if err != nil {
return err
}
return c.Attachment(filePath, filepath.Base(filePath))
filePath, contentType := audio.NormalizeAudioFile(filePath)
if contentType != "" {
c.Response().Header().Set("Content-Type", contentType)
}
return c.Attachment(filePath, filepath.Base(filePath))
}
}

View File

@@ -8,6 +8,7 @@ import (
"github.com/mudler/LocalAI/core/config"
"github.com/mudler/LocalAI/core/http/middleware"
"github.com/mudler/LocalAI/core/schema"
"github.com/mudler/LocalAI/pkg/audio"
"github.com/mudler/LocalAI/pkg/model"
"github.com/mudler/xlog"
)
@@ -39,6 +40,10 @@ func TTSEndpoint(cl *config.ModelConfigLoader, ml *model.ModelLoader, appConfig
if err != nil {
return err
}
filePath, contentType := audio.NormalizeAudioFile(filePath)
if contentType != "" {
c.Response().Header().Set("Content-Type", contentType)
}
return c.Attachment(filePath, filepath.Base(filePath))
}
}

View File

@@ -7,12 +7,11 @@ 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/mudler/LocalAI/core/schema"
"github.com/mudler/xlog"
"github.com/mudler/LocalAI/pkg/audio"
"github.com/mudler/LocalAI/pkg/model"
"github.com/mudler/LocalAI/pkg/utils"
"github.com/mudler/xlog"
)
// TTSEndpoint is the OpenAI Speech API endpoint https://platform.openai.com/docs/api-reference/audio/createSpeech
@@ -86,6 +85,10 @@ func TTSEndpoint(cl *config.ModelConfigLoader, ml *model.ModelLoader, appConfig
return err
}
filePath, contentType := audio.NormalizeAudioFile(filePath)
if contentType != "" {
c.Response().Header().Set("Content-Type", contentType)
}
return c.Attachment(filePath, filepath.Base(filePath))
}
}