2023-07-20 20:10:12 +00:00
|
|
|
package backend
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
config "github.com/go-skynet/LocalAI/api/config"
|
|
|
|
|
|
|
|
"github.com/go-skynet/LocalAI/api/options"
|
|
|
|
"github.com/go-skynet/LocalAI/pkg/grpc/proto"
|
|
|
|
"github.com/go-skynet/LocalAI/pkg/grpc/whisper/api"
|
|
|
|
model "github.com/go-skynet/LocalAI/pkg/model"
|
|
|
|
)
|
|
|
|
|
|
|
|
func ModelTranscription(audio, language string, loader *model.ModelLoader, c config.Config, o *options.Option) (*api.Result, error) {
|
2023-08-18 23:49:33 +00:00
|
|
|
|
|
|
|
opts := modelOpts(c, o, []model.Option{
|
2023-07-20 20:10:12 +00:00
|
|
|
model.WithBackendString(model.WhisperBackend),
|
2023-08-07 20:39:10 +00:00
|
|
|
model.WithModel(c.Model),
|
2023-07-20 20:10:12 +00:00
|
|
|
model.WithContext(o.Context),
|
|
|
|
model.WithThreads(uint32(c.Threads)),
|
|
|
|
model.WithAssetDir(o.AssetsDestination),
|
2023-08-18 23:49:33 +00:00
|
|
|
})
|
2023-07-20 20:10:12 +00:00
|
|
|
|
|
|
|
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),
|
|
|
|
})
|
|
|
|
}
|