MCPcopy
hub / github.com/mudler/LocalAI / SoundGeneration

Function SoundGeneration

core/backend/soundgeneration.go:17–151  ·  view source on GitHub ↗
(
	ctx context.Context,
	text string,
	duration *float32,
	temperature *float32,
	doSample *bool,
	sourceFile *string,
	sourceDivisor *int32,
	think *bool,
	caption string,
	lyrics string,
	bpm *int32,
	keyscale string,
	language string,
	timesignature string,
	instrumental *bool,
	loader *model.ModelLoader,
	appConfig *config.ApplicationConfig,
	modelConfig config.ModelConfig,
)

Source from the content-addressed store, hash-verified

15)
16
17func SoundGeneration(
18 ctx context.Context,
19 text string,
20 duration *float32,
21 temperature *float32,
22 doSample *bool,
23 sourceFile *string,
24 sourceDivisor *int32,
25 think *bool,
26 caption string,
27 lyrics string,
28 bpm *int32,
29 keyscale string,
30 language string,
31 timesignature string,
32 instrumental *bool,
33 loader *model.ModelLoader,
34 appConfig *config.ApplicationConfig,
35 modelConfig config.ModelConfig,
36) (string, *proto.Result, error) {
37
38 opts := ModelOptions(modelConfig, appConfig)
39 soundGenModel, err := loader.Load(opts...)
40 if err != nil {
41 recordModelLoadFailure(appConfig, modelConfig.Name, modelConfig.Backend, err, nil)
42 return "", nil, err
43 }
44
45 if soundGenModel == nil {
46 return "", nil, fmt.Errorf("could not load sound generation model")
47 }
48
49 if err := os.MkdirAll(appConfig.GeneratedContentDir, 0750); err != nil {
50 return "", nil, fmt.Errorf("failed creating audio directory: %s", err)
51 }
52
53 audioDir := filepath.Join(appConfig.GeneratedContentDir, "audio")
54 if err := os.MkdirAll(audioDir, 0750); err != nil {
55 return "", nil, fmt.Errorf("failed creating audio directory: %s", err)
56 }
57
58 fileName := utils.GenerateUniqueFileName(audioDir, "sound_generation", ".wav")
59 filePath := filepath.Join(audioDir, fileName)
60 if filePath, err = filepath.Abs(filePath); err != nil {
61 return "", nil, fmt.Errorf("failed resolving sound generation path: %w", err)
62 }
63
64 req := &proto.SoundGenerationRequest{
65 Text: text,
66 Model: modelConfig.Model,
67 Dst: filePath,
68 Sample: doSample,
69 Duration: duration,
70 Temperature: temperature,
71 Src: sourceFile,
72 SrcDivisor: sourceDivisor,
73 }
74 if think != nil {

Callers 2

SoundGenerationEndpointFunction · 0.92
RunMethod · 0.92

Calls 9

GenerateUniqueFileNameFunction · 0.92
TruncateStringFunction · 0.92
RecordBackendTraceFunction · 0.92
ModelOptionsFunction · 0.85
recordModelLoadFailureFunction · 0.85
LoadMethod · 0.65
SoundGenerationMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected