624e24ba49
- Added ASR configuration options to the knowledge base and model settings. - Implemented ASR model selection and transcription capabilities in the knowledge processing pipeline. - Enhanced file upload support to include audio formats for ASR processing. - Updated localization files to include ASR-related labels and descriptions. - Refactored model handling to accommodate ASR as a new model type.
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package asr
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/Tencent/WeKnora/internal/types"
|
|
)
|
|
|
|
// ASR defines the interface for Automatic Speech Recognition model operations.
|
|
type ASR interface {
|
|
// Transcribe sends audio bytes to the ASR model and returns the transcribed text.
|
|
Transcribe(ctx context.Context, audioBytes []byte, fileName string) (string, error)
|
|
|
|
GetModelName() string
|
|
GetModelID() string
|
|
}
|
|
|
|
// Config holds the configuration needed to create an ASR instance.
|
|
type Config struct {
|
|
Source types.ModelSource
|
|
BaseURL string
|
|
ModelName string
|
|
APIKey string
|
|
ModelID string
|
|
InterfaceType string // "openai" (default)
|
|
Language string // optional: specify language for transcription
|
|
}
|
|
|
|
// NewASR creates an ASR instance based on the provided configuration.
|
|
func NewASR(config *Config) (ASR, error) {
|
|
ifType := strings.ToLower(config.InterfaceType)
|
|
if ifType == "" {
|
|
ifType = "openai"
|
|
}
|
|
|
|
switch ifType {
|
|
case "openai":
|
|
return NewOpenAIASR(config)
|
|
default:
|
|
return nil, fmt.Errorf("unsupported ASR interface type: %s", ifType)
|
|
}
|
|
}
|