-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: elevenlabs
sound-generation
api (#3355)
* initial version of elevenlabs compatible soundgeneration api and cli command Signed-off-by: Dave Lee <[email protected]> * minor cleanup Signed-off-by: Dave Lee <[email protected]> * restore TTS, add test Signed-off-by: Dave Lee <[email protected]> * remove stray s Signed-off-by: Dave Lee <[email protected]> * fix Signed-off-by: Dave Lee <[email protected]> --------- Signed-off-by: Dave Lee <[email protected]> Signed-off-by: Ettore Di Giacinto <[email protected]> Co-authored-by: Ettore Di Giacinto <[email protected]>
- Loading branch information
1 parent
84d6e5a
commit 81ae92f
Showing
20 changed files
with
450 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package backend | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/mudler/LocalAI/core/config" | ||
"github.com/mudler/LocalAI/pkg/grpc/proto" | ||
"github.com/mudler/LocalAI/pkg/model" | ||
"github.com/mudler/LocalAI/pkg/utils" | ||
) | ||
|
||
func SoundGeneration( | ||
backend string, | ||
modelFile string, | ||
text string, | ||
duration *float32, | ||
temperature *float32, | ||
doSample *bool, | ||
sourceFile *string, | ||
sourceDivisor *int32, | ||
loader *model.ModelLoader, | ||
appConfig *config.ApplicationConfig, | ||
backendConfig config.BackendConfig, | ||
) (string, *proto.Result, error) { | ||
if backend == "" { | ||
return "", nil, fmt.Errorf("backend is a required parameter") | ||
} | ||
|
||
grpcOpts := gRPCModelOpts(backendConfig) | ||
opts := modelOpts(config.BackendConfig{}, appConfig, []model.Option{ | ||
model.WithBackendString(backend), | ||
model.WithModel(modelFile), | ||
model.WithContext(appConfig.Context), | ||
model.WithAssetDir(appConfig.AssetsDestination), | ||
model.WithLoadGRPCLoadModelOpts(grpcOpts), | ||
}) | ||
|
||
soundGenModel, err := loader.BackendLoader(opts...) | ||
if err != nil { | ||
return "", nil, err | ||
} | ||
|
||
if soundGenModel == nil { | ||
return "", nil, fmt.Errorf("could not load sound generation model") | ||
} | ||
|
||
if err := os.MkdirAll(appConfig.AudioDir, 0750); err != nil { | ||
return "", nil, fmt.Errorf("failed creating audio directory: %s", err) | ||
} | ||
|
||
fileName := utils.GenerateUniqueFileName(appConfig.AudioDir, "sound_generation", ".wav") | ||
filePath := filepath.Join(appConfig.AudioDir, fileName) | ||
|
||
res, err := soundGenModel.SoundGeneration(context.Background(), &proto.SoundGenerationRequest{ | ||
Text: text, | ||
Model: modelFile, | ||
Dst: filePath, | ||
Sample: doSample, | ||
Duration: duration, | ||
Temperature: temperature, | ||
Src: sourceFile, | ||
SrcDivisor: sourceDivisor, | ||
}) | ||
|
||
// return RPC error if any | ||
if !res.Success { | ||
return "", nil, fmt.Errorf(res.Message) | ||
} | ||
|
||
return filePath, res, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.