Skip to content

Formerly KrillinAI, VideoTranslation and Dubbing Tool for 120+ Languages. Open-source AI workspace for creators, powered by Codex. Video downloader, video translation, create videos, images, audios, and edits with Agents in one place. For your Social Media like YouTube, TikTok, Instagram, etc.

fix: dubbing timeout

沈浩7cb70fb6cb5d
diff --git a/internal/service/audio2subtitle.go b/internal/service/audio2subtitle.go
index ef7670e5..13785e4d 100644
--- a/internal/service/audio2subtitle.go
+++ b/internal/service/audio2subtitle.go
@@ -100,7 +100,6 @@ func (s Service) audioToSrt(ctx context.Context, stepParam *types.SubtitleTaskSt
parallelControlChan = make(chan struct{}, config.Conf.App.TranslateParallelNum)
eg *errgroup.Group
stepNumMu sync.Mutex
- err error
)
ctx, cancel = context.WithCancel(ctx)
defer cancel()
@@ -115,6 +114,7 @@ func (s Service) audioToSrt(ctx context.Context, stepParam *types.SubtitleTaskSt
log.GetLogger().Error("audioToSubtitle.audioToSrt panic recovered", zap.Any("panic", r), zap.String("stack", string(debug.Stack())))
}
}()
+ var err error
select {
case <-ctx.Done():
return ctx.Err()
@@ -176,7 +176,7 @@ func (s Service) audioToSrt(ctx context.Context, stepParam *types.SubtitleTaskSt
})
}
- if err = eg.Wait(); err != nil {
+ if err := eg.Wait(); err != nil {
log.GetLogger().Error("audioToSubtitle audioToSrt eg.Wait err", zap.Any("taskId", stepParam.TaskId), zap.Error(err))
return fmt.Errorf("audioToSubtitle audioToSrt eg.Wait err: %w", err)
}
@@ -199,7 +199,7 @@ func (s Service) audioToSrt(ctx context.Context, stepParam *types.SubtitleTaskSt
// 合并原始无时间戳字幕
originNoTsFile := fmt.Sprintf("%s/%s", stepParam.TaskBasePath, types.SubtitleTaskSrtNoTimestampFileName)
- err = util.MergeFile(originNoTsFile, originNoTsFiles...)
+ err := util.MergeFile(originNoTsFile, originNoTsFiles...)
if err != nil {
log.GetLogger().Error("audioToSubtitle audioToSrt merge originNoTsFile err",
zap.Any("stepParam", stepParam), zap.Error(err))
diff --git a/pkg/aliyun/base.go b/pkg/aliyun/base.go
index afce8082..e929f791 100644
--- a/pkg/aliyun/base.go
+++ b/pkg/aliyun/base.go
@@ -5,6 +5,7 @@ import (
"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
"go.uber.org/zap"
+ "krillin-ai/config"
"krillin-ai/log"
)
@@ -22,6 +23,9 @@ func CreateToken(ak, sk string) (string, error) {
if err != nil {
return "", err
}
+ if config.Conf.App.Proxy != "" {
+ client.SetHttpProxy(config.Conf.App.Proxy)
+ }
request := requests.NewCommonRequest()
request.Method = "POST"
request.Domain = "nls-meta.cn-shanghai.aliyuncs.com"
diff --git a/pkg/aliyun/tts.go b/pkg/aliyun/tts.go
index 46b25d25..923ea352 100644
--- a/pkg/aliyun/tts.go
+++ b/pkg/aliyun/tts.go
@@ -5,8 +5,10 @@ import (
"fmt"
"github.com/gorilla/websocket"
"go.uber.org/zap"
+ "krillin-ai/config"
"krillin-ai/log"
"krillin-ai/pkg/util"
+ "net/http"
"os"
"time"
)
@@ -64,6 +66,9 @@ func (c *TtsClient) Text2Speech(text, voice, outputFile string) error {
token, _ := CreateToken(c.AccessKeyID, c.AccessKeySecret)
fullURL := "wss://nls-gateway-cn-beijing.aliyuncs.com/ws/v1?token=" + token
dialer := websocket.DefaultDialer
+ if config.Conf.App.Proxy != "" {
+ dialer.Proxy = http.ProxyURL(config.Conf.App.ParsedProxy)
+ }
dialer.HandshakeTimeout = 10 * time.Second
conn, _, err = dialer.Dial(fullURL, nil)
if err != nil {