Skip to content

Commit

Permalink
TTS endpoint: add optional lang parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
blob42 committed Apr 23, 2024
1 parent c70cb9a commit 55251d3
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 65 deletions.
3 changes: 2 additions & 1 deletion backend/backend.proto
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ message TTSRequest {
string model = 2;
string dst = 3;
string voice = 4;
optional string lang = 5;
}

message TokenizationResponse {
Expand All @@ -264,4 +265,4 @@ message StatusResponse {
message Message {
string role = 1;
string content = 2;
}
}
2 changes: 1 addition & 1 deletion backend/python/coqui/coqui_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def LoadModel(self, request, context):
def TTS(self, request, context):
try:
# if model is multilangual add language from request or env as fallback
lang = request.Lang or COQUI_LANGUAGE
lang = request.lang or COQUI_LANGUAGE
if self.tts.is_multi_lingual and lang is None:
return backend_pb2.Result(success=False, message=f"Model is multi-lingual, but no language was provided")

Expand Down
3 changes: 2 additions & 1 deletion core/backend/tts.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func generateUniqueFileName(dir, baseName, ext string) string {
}
}

func ModelTTS(backend, text, modelFile, voice string, loader *model.ModelLoader, appConfig *config.ApplicationConfig, backendConfig config.BackendConfig) (string, *proto.Result, error) {
func ModelTTS(backend, text, modelFile, voice string, lang string, loader *model.ModelLoader, appConfig *config.ApplicationConfig, backendConfig config.BackendConfig) (string, *proto.Result, error) {
bb := backend
if bb == "" {
bb = model.PiperBackend
Expand Down Expand Up @@ -83,6 +83,7 @@ func ModelTTS(backend, text, modelFile, voice string, loader *model.ModelLoader,
Model: modelPath,
Voice: voice,
Dst: filePath,
Lang: &lang,
})

// return RPC error if any
Expand Down
3 changes: 2 additions & 1 deletion core/cli/tts.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type TTSCMD struct {
Backend string `short:"b" default:"piper" help:"Backend to run the TTS model"`
Model string `short:"m" required:"" help:"Model name to run the TTS"`
Voice string `short:"v" help:"Voice name to run the TTS"`
Lang string `short:"l" help:"Language to use with the TTS"`
OutputFile string `short:"o" type:"path" help:"The path to write the output wav file"`
ModelsPath string `env:"LOCALAI_MODELS_PATH,MODELS_PATH" type:"path" default:"${basepath}/models" help:"Path containing models used for inferencing" group:"storage"`
BackendAssetsPath string `env:"LOCALAI_BACKEND_ASSETS_PATH,BACKEND_ASSETS_PATH" type:"path" default:"/tmp/localai/backend_data" help:"Path used to extract libraries that are required by some of the backends in runtime" group:"storage"`
Expand Down Expand Up @@ -45,7 +46,7 @@ func (t *TTSCMD) Run(ctx *Context) error {
options := config.BackendConfig{}
options.SetDefaults()

filePath, _, err := backend.ModelTTS(t.Backend, text, t.Model, t.Voice, ml, opts, options)
filePath, _, err := backend.ModelTTS(t.Backend, text, t.Model, t.Voice, t.Lang, ml, opts, options)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion core/http/endpoints/elevenlabs/tts.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TTSEndpoint(cl *config.BackendConfigLoader, ml *model.ModelLoader, appConfi
}
log.Debug().Msgf("Request for model: %s", modelFile)

filePath, _, err := backend.ModelTTS(cfg.Backend, input.Text, modelFile, voiceID, ml, appConfig, *cfg)
filePath, _, err := backend.ModelTTS(cfg.Backend, input.Text, modelFile, "",voiceID, ml, appConfig, *cfg)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion core/http/endpoints/localai/tts.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TTSEndpoint(cl *config.BackendConfigLoader, ml *model.ModelLoader, appConfi
cfg.Backend = input.Backend
}

filePath, _, err := backend.ModelTTS(cfg.Backend, input.Input, modelFile, input.Voice, ml, appConfig, *cfg)
filePath, _, err := backend.ModelTTS(cfg.Backend, input.Input, modelFile, input.Voice, input.Lang, ml, appConfig, *cfg)
if err != nil {
return err
}
Expand Down
119 changes: 60 additions & 59 deletions core/schema/localai.go
Original file line number Diff line number Diff line change
@@ -1,59 +1,60 @@
package schema

import (
gopsutil "github.com/shirou/gopsutil/v3/process"
)

type BackendMonitorRequest struct {
Model string `json:"model" yaml:"model"`
}

type BackendMonitorResponse struct {
MemoryInfo *gopsutil.MemoryInfoStat
MemoryPercent float32
CPUPercent float64
}

type TTSRequest struct {
Model string `json:"model" yaml:"model"`
Input string `json:"input" yaml:"input"`
Voice string `json:"voice" yaml:"voice"`
Backend string `json:"backend" yaml:"backend"`
}

type StoresSet struct {
Store string `json:"store,omitempty" yaml:"store,omitempty"`

Keys [][]float32 `json:"keys" yaml:"keys"`
Values []string `json:"values" yaml:"values"`
}

type StoresDelete struct {
Store string `json:"store,omitempty" yaml:"store,omitempty"`

Keys [][]float32 `json:"keys"`
}

type StoresGet struct {
Store string `json:"store,omitempty" yaml:"store,omitempty"`

Keys [][]float32 `json:"keys" yaml:"keys"`
}

type StoresGetResponse struct {
Keys [][]float32 `json:"keys" yaml:"keys"`
Values []string `json:"values" yaml:"values"`
}

type StoresFind struct {
Store string `json:"store,omitempty" yaml:"store,omitempty"`

Key []float32 `json:"key" yaml:"key"`
Topk int `json:"topk" yaml:"topk"`
}

type StoresFindResponse struct {
Keys [][]float32 `json:"keys" yaml:"keys"`
Values []string `json:"values" yaml:"values"`
Similarities []float32 `json:"similarities" yaml:"similarities"`
}
package schema

import (
gopsutil "github.com/shirou/gopsutil/v3/process"
)

type BackendMonitorRequest struct {
Model string `json:"model" yaml:"model"`
}

type BackendMonitorResponse struct {
MemoryInfo *gopsutil.MemoryInfoStat
MemoryPercent float32
CPUPercent float64
}

type TTSRequest struct {
Model string `json:"model" yaml:"model"`
Input string `json:"input" yaml:"input"`
Voice string `json:"voice" yaml:"voice"`
Backend string `json:"backend" yaml:"backend"`
Lang string `json:"lang,omitempty" yaml:"lang,omitempty"`
}

type StoresSet struct {
Store string `json:"store,omitempty" yaml:"store,omitempty"`

Keys [][]float32 `json:"keys" yaml:"keys"`
Values []string `json:"values" yaml:"values"`
}

type StoresDelete struct {
Store string `json:"store,omitempty" yaml:"store,omitempty"`

Keys [][]float32 `json:"keys"`
}

type StoresGet struct {
Store string `json:"store,omitempty" yaml:"store,omitempty"`

Keys [][]float32 `json:"keys" yaml:"keys"`
}

type StoresGetResponse struct {
Keys [][]float32 `json:"keys" yaml:"keys"`
Values []string `json:"values" yaml:"values"`
}

type StoresFind struct {
Store string `json:"store,omitempty" yaml:"store,omitempty"`

Key []float32 `json:"key" yaml:"key"`
Topk int `json:"topk" yaml:"topk"`
}

type StoresFindResponse struct {
Keys [][]float32 `json:"keys" yaml:"keys"`
Values []string `json:"values" yaml:"values"`
Similarities []float32 `json:"similarities" yaml:"similarities"`
}

0 comments on commit 55251d3

Please sign in to comment.