feat(video): update ASR terminology and file type labels for improved clarity

- Changed 'Audio Processing' to 'Audio & Video' in English, Korean, Russian, and Chinese translations to reflect expanded functionality.
- Updated ASR configuration titles and descriptions to include video processing capabilities, enhancing user understanding of the feature.
- Renamed file type labels from 'Audio Files' to 'Audio & Video' across multiple languages for consistency and clarity.
- Enhanced document upload handling in the KnowledgeBase to filter unsupported file types, providing user feedback for filtered images, videos, and audio files.

This update improves the internationalization of the application and clarifies the capabilities of the ASR feature.
This commit is contained in:
wizardchen
2026-04-14 22:27:31 +08:00
committed by lyingbug
parent cb97489787
commit 0fcab3a413
23 changed files with 635 additions and 291 deletions
+15 -2
View File
@@ -6,10 +6,23 @@ import (
"github.com/Tencent/WeKnora/internal/types"
)
// Segment represents a transcribed segment with timestamps.
type Segment struct {
Start float64 `json:"start"`
End float64 `json:"end"`
Text string `json:"text"`
}
// TranscriptionResult holds the full text and its segments.
type TranscriptionResult struct {
Text string `json:"text"`
Segments []Segment `json:"segments,omitempty"`
}
// 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)
// Transcribe sends audio bytes to the ASR model and returns the transcribed text and segments.
Transcribe(ctx context.Context, audioBytes []byte, fileName string) (*TranscriptionResult, error)
GetModelName() string
GetModelID() string
+25 -5
View File
@@ -3,6 +3,7 @@ package asr
import (
"bytes"
"context"
"encoding/json"
"fmt"
"net/http"
"path/filepath"
@@ -44,9 +45,9 @@ func NewOpenAIASR(config *Config) (*OpenAIASR, error) {
}
// Transcribe sends audio bytes to the OpenAI-compatible audio transcriptions API.
func (s *OpenAIASR) Transcribe(ctx context.Context, audioBytes []byte, fileName string) (string, error) {
func (s *OpenAIASR) Transcribe(ctx context.Context, audioBytes []byte, fileName string) (*TranscriptionResult, error) {
if len(audioBytes) == 0 {
return "", fmt.Errorf("audio bytes are empty")
return nil, fmt.Errorf("audio bytes are empty")
}
// Ensure fileName has an extension for proper MIME type detection
@@ -61,7 +62,7 @@ func (s *OpenAIASR) Transcribe(ctx context.Context, audioBytes []byte, fileName
Model: s.modelName,
FilePath: fileName,
Reader: bytes.NewReader(audioBytes),
Format: openai.AudioResponseFormatJSON,
Format: openai.AudioResponseFormatVerboseJSON,
}
if s.language != "" {
@@ -70,12 +71,31 @@ func (s *OpenAIASR) Transcribe(ctx context.Context, audioBytes []byte, fileName
resp, err := s.client.CreateTranscription(ctx, req)
if err != nil {
return "", fmt.Errorf("ASR transcription request failed: %w", err)
return nil, fmt.Errorf("ASR transcription request failed: %w", err)
}
jsonData, err := json.Marshal(resp)
if err != nil {
return nil, fmt.Errorf("marshal transcription response: %w", err)
}
logger.Debugf(ctx, "[ASR] Transcription response: %s", string(jsonData))
text := strings.TrimSpace(resp.Text)
logger.Infof(ctx, "[ASR] Transcription completed, text length=%d", len(text))
return text, nil
var segments []Segment
for _, s := range resp.Segments {
segments = append(segments, Segment{
Start: s.Start,
End: s.End,
Text: strings.TrimSpace(s.Text),
})
}
return &TranscriptionResult{
Text: text,
Segments: segments,
}, nil
}
func (s *OpenAIASR) GetModelName() string { return s.modelName }