You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

81 lines
2.5 KiB

package echomeet
import (
"context"
"fmt"
"yunyan/pb"
msspeech "yunyan/sys/microsoft/speech"
mstranslate "yunyan/sys/microsoft/translate"
"yunyan/sys/openai"
)
// 微软系单元服务实例(由 provider_registry.go 按服务池字段构造):
// 转写=Azure Speech Batch、翻译=Azure Translator。
// 总结(Azure OpenAI)走 OpenAI 兼容端点(openaiSummarizer)。
// Azure Speech Batch Transcription
type microsoftTranscriber struct {
sys msspeech.ISys
}
func (this *microsoftTranscriber) Submit(_ context.Context, req SubmitRequest) (*SubmitResult, error) {
taskID, err := this.sys.CreateTask(req.AudioURL, req.Language, req.EnableSpeaker, req.CallbackURL)
if err != nil {
return nil, fmt.Errorf("microsoft speech create task: %w", err)
}
return &SubmitResult{TaskID: taskID}, nil
}
func (this *microsoftTranscriber) Query(_ context.Context, taskID, _ string) (*QueryResult, error) {
status, contexts, err := this.sys.QueryTask(taskID)
switch status {
case msspeech.StatusSuccess:
out := make([]*pb.ContextStruct, 0, len(contexts))
for _, c := range contexts {
out = append(out, &pb.ContextStruct{
Content: c.Content,
Starttime: c.StartTime,
Endtime: c.EndTime,
Speaker: c.Speaker,
})
}
return &QueryResult{Status: StatusSuccess, Contexts: out}, nil
case msspeech.StatusRunning:
return &QueryResult{Status: StatusRunning}, nil
default:
return &QueryResult{Status: StatusFailed}, fmt.Errorf("microsoft speech query failed: %w", err)
}
}
// Azure Translator
type microsoftTranslator struct {
sys mstranslate.ISys
}
func (this *microsoftTranslator) Translate(ctx context.Context, from, to string, texts []string) ([]string, error) {
return this.sys.Translate(ctx, toMicrosoftTranslateLang(from), toMicrosoftTranslateLang(to), texts)
}
// openaiSummarizer OpenAI 兼容端点总结(openai/qwen/deepseek/azure openai…共用)。
type openaiSummarizer struct {
sys openai.ISys
}
func (this *openaiSummarizer) Chat(ctx context.Context, messages []ChatMessage) (string, error) {
if this.sys == nil {
return "", fmt.Errorf("openai-compatible summarizer not initialized")
}
msgs := make([]openai.ChatReq, 0, len(messages))
for _, m := range messages {
msgs = append(msgs, openai.ChatReq{Role: m.Role, Content: m.Content, Images: m.Images})
}
resp, err := this.sys.Chat(ctx, msgs)
if err != nil {
return "", err
}
if resp == nil {
return "", fmt.Errorf("openai-compatible chat: empty response")
}
return resp.Content, nil
}