2024-01-05 17:04:46 +00:00
|
|
|
package backend
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
2024-02-21 01:21:19 +00:00
|
|
|
config "github.com/go-skynet/LocalAI/core/config"
|
|
|
|
"github.com/go-skynet/LocalAI/core/schema"
|
2024-01-05 17:04:46 +00:00
|
|
|
|
2024-02-21 01:21:19 +00:00
|
|
|
"github.com/go-skynet/LocalAI/core/options"
|
2024-01-05 17:04:46 +00:00
|
|
|
"github.com/go-skynet/LocalAI/pkg/grpc/proto"
|
|
|
|
model "github.com/go-skynet/LocalAI/pkg/model"
|
|
|
|
)
|
|
|
|
|
|
|
|
func ModelTranscription(audio, language string, loader *model.ModelLoader, c config.Config, o *options.Option) (*schema.Result, error) {
|
|
|
|
|
|
|
|
opts := modelOpts(c, o, []model.Option{
|
|
|
|
model.WithBackendString(model.WhisperBackend),
|
|
|
|
model.WithModel(c.Model),
|
|
|
|
model.WithContext(o.Context),
|
|
|
|
model.WithThreads(uint32(c.Threads)),
|
|
|
|
model.WithAssetDir(o.AssetsDestination),
|
|
|
|
})
|
|
|
|
|
|
|
|
whisperModel, err := o.Loader.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,
|
|
|
|
Threads: uint32(c.Threads),
|
|
|
|
})
|
|
|
|
}
|