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.
62 lines
2.1 KiB
62 lines
2.1 KiB
package echomeet
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"yunyan/pb"
|
|
"yunyan/sys/aliyun/filetrans"
|
|
alitranslate "yunyan/sys/aliyun/translate"
|
|
)
|
|
|
|
// 阿里系单元服务实例(由 provider_registry.go 按服务池字段构造):
|
|
// 转写=DashScope 录音文件转写(paraformer-v2,异步)、翻译=阿里翻译。
|
|
// 总结(通义千问)走 OpenAI 兼容端点,见 provider_registry.go 的 openaiSummarizer。
|
|
//
|
|
// 语言支持过滤已上移到编排层:服务池 asrfile_alibaba 模板的 languages 字段 seed 了
|
|
// paraformer-v2 实际支持的语种,选路时不支持的语言会跳过本服务(原 SupportsLanguage 白名单
|
|
// 的职责由后台配置接管——把西语送进 paraformer-v2 会静默返回空转写,务必别放开 languages)。
|
|
|
|
// 阿里云 DashScope 转写
|
|
type aliTranscriber struct {
|
|
sys filetrans.ISys
|
|
}
|
|
|
|
func (this *aliTranscriber) Submit(_ context.Context, req SubmitRequest) (*SubmitResult, error) {
|
|
aliLang := toDashScopeLang(req.Language)
|
|
taskID, err := this.sys.CreateTask(req.AudioURL, aliLang, req.EnableSpeaker, req.CallbackURL)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("ali filetrans create task: %w", err)
|
|
}
|
|
return &SubmitResult{TaskID: taskID}, nil
|
|
}
|
|
|
|
func (this *aliTranscriber) Query(_ context.Context, taskID, _ string) (*QueryResult, error) {
|
|
status, contexts, err := this.sys.QueryTask(taskID)
|
|
switch status {
|
|
case filetrans.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 filetrans.StatusRunning:
|
|
return &QueryResult{Status: StatusRunning}, nil
|
|
default:
|
|
return &QueryResult{Status: StatusFailed}, fmt.Errorf("ali filetrans query failed: %w", err)
|
|
}
|
|
}
|
|
|
|
// 阿里翻译
|
|
type aliTranslator struct {
|
|
sys alitranslate.ISys
|
|
}
|
|
|
|
func (this *aliTranslator) Translate(ctx context.Context, from, to string, texts []string) ([]string, error) {
|
|
return this.sys.Translate(ctx, toAliTranslateLang(from), toAliTranslateLang(to), texts)
|
|
}
|
|
|