2024-01-05 17:04:46 +00:00
|
|
|
package backend
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
2024-03-01 15:19:53 +00:00
|
|
|
"github.com/go-skynet/LocalAI/core/config"
|
2024-02-21 01:21:19 +00:00
|
|
|
"github.com/go-skynet/LocalAI/core/schema"
|
2024-01-05 17:04:46 +00:00
|
|
|
|
|
|
|
"github.com/go-skynet/LocalAI/pkg/grpc/proto"
|
2024-04-17 21:33:49 +00:00
|
|
|
model "github.com/go-skynet/LocalAI/pkg/model"
|
2024-01-05 17:04:46 +00:00
|
|
|
)
|
|
|
|
|
2024-04-29 17:42:37 +00:00
|
|
|
func ModelTranscription(audio, language string, ml *model.ModelLoader, backendConfig config.BackendConfig, appConfig *config.ApplicationConfig) (*schema.TranscriptionResult, error) {
|
2024-01-05 17:04:46 +00:00
|
|
|
|
2024-03-01 15:19:53 +00:00
|
|
|
opts := modelOpts(backendConfig, appConfig, []model.Option{
|
2024-01-05 17:04:46 +00:00
|
|
|
model.WithBackendString(model.WhisperBackend),
|
2024-03-01 15:19:53 +00:00
|
|
|
model.WithModel(backendConfig.Model),
|
|
|
|
model.WithContext(appConfig.Context),
|
2024-03-13 09:05:30 +00:00
|
|
|
model.WithThreads(uint32(*backendConfig.Threads)),
|
2024-03-01 15:19:53 +00:00
|
|
|
model.WithAssetDir(appConfig.AssetsDestination),
|
2024-01-05 17:04:46 +00:00
|
|
|
})
|
|
|
|
|
2024-03-01 15:19:53 +00:00
|
|
|
whisperModel, err := ml.BackendLoader(opts...)
|
2024-01-05 17:04:46 +00:00
|
|
|
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,
|
2024-03-13 09:05:30 +00:00
|
|
|
Threads: uint32(*backendConfig.Threads),
|
2024-01-05 17:04:46 +00:00
|
|
|
})
|
|
|
|
}
|