mirror of
https://github.com/mudler/LocalAI.git
synced 2024-12-18 20:27:57 +00:00
03b1cf51fd
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
package backend
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/mudler/LocalAI/core/config"
|
|
"github.com/mudler/LocalAI/core/schema"
|
|
|
|
"github.com/mudler/LocalAI/pkg/grpc/proto"
|
|
model "github.com/mudler/LocalAI/pkg/model"
|
|
)
|
|
|
|
func ModelTranscription(audio, language string, translate bool, ml *model.ModelLoader, backendConfig config.BackendConfig, appConfig *config.ApplicationConfig) (*schema.TranscriptionResult, error) {
|
|
|
|
opts := modelOpts(backendConfig, appConfig, []model.Option{
|
|
model.WithBackendString(model.WhisperBackend),
|
|
model.WithModel(backendConfig.Model),
|
|
model.WithContext(appConfig.Context),
|
|
model.WithThreads(uint32(*backendConfig.Threads)),
|
|
model.WithAssetDir(appConfig.AssetsDestination),
|
|
})
|
|
|
|
whisperModel, err := ml.BackendLoader(opts...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if whisperModel == nil {
|
|
return nil, fmt.Errorf("could not load whisper model")
|
|
}
|
|
|
|
return whisperModel.AudioTranscription(context.Background(), &proto.TranscriptRequest{
|
|
Dst: audio,
|
|
Language: language,
|
|
Translate: translate,
|
|
Threads: uint32(*backendConfig.Threads),
|
|
})
|
|
}
|