Compare commits

6 Commits
v1.0.0 ... main

Author SHA1 Message Date
zuoban
1f7fab5c0b feat: add logging for endpoint requests and responses in client and utils 2025-08-12 14:33:51 +08:00
zuoban
f849a2f5ea feat: reduce voices cache expiry time from 24 hours to 2 hours 2025-08-12 14:16:22 +08:00
zuoban
93fd842f64 Merge remote-tracking branch 'origin/main'
# Conflicts:
#	internal/tts/microsoft/client.go
2025-08-12 14:10:50 +08:00
zuoban
901bb4c3d1 feat: add logging for voice list retrieval from cache and fix loading option text 2025-08-12 14:10:11 +08:00
zuoban
99fd935ae9 feat: add logging for voice list retrieval from cache and fix loading option text 2025-08-12 14:09:04 +08:00
王锦强
66421eebec Updates Docker config path and ignores system files
Changes Docker volume mount path from /app/configs to /configs for simpler container structure.

Adds .DS_Store to gitignore for macOS compatibility and normalizes .idea/ entry to .idea for consistency.

#20
2025-08-06 22:43:02 +08:00
5 changed files with 15 additions and 10 deletions

3
.gitignore vendored
View File

@@ -25,4 +25,5 @@ go.work.sum
# env file
.env
.idea/
.DS_Store
.idea

View File

@@ -86,12 +86,12 @@ curl -X POST "http://localhost:8080/v1/audio/speech" \
docker run -d -p 9000:9000 -e PORT=9000 --name=tts zuoban/zb-tts
# 使用配置文件
docker run -d -p 8080:8080 -v /path/to/config.yaml:/app/configs/config.yaml --name=tts zuoban/zb-tts
docker run -d -p 8080:8080 -v /path/to/config.yaml:/configs/config.yaml --name=tts zuoban/zb-tts
```
### 配置文件详解
TTS 服务使用 YAML 格式的配置文件,默认位置为 `/app/configs/config.yaml`。以下是配置文件的主要选项:
TTS 服务使用 YAML 格式的配置文件,默认位置为 `/configs/config.yaml`。以下是配置文件的主要选项:
```yaml
server:

View File

@@ -117,6 +117,8 @@ func (c *Client) ListVoices(ctx context.Context, locale string) ([]models.Voice,
// 检查缓存是否有效
c.voicesCacheMu.RLock()
if !c.voicesCacheExpiry.IsZero() && time.Now().Before(c.voicesCacheExpiry) && len(c.voicesCache) > 0 {
// 从缓存中获取
log.Println("ListVoices 从缓存中获取语音列表: ", len(c.voicesCache), "个", "剩余时间:", c.voicesCacheExpiry.Sub(time.Now()))
voices := c.voicesCache
c.voicesCacheMu.RUnlock()
@@ -135,12 +137,14 @@ func (c *Client) ListVoices(ctx context.Context, locale string) ([]models.Voice,
c.voicesCacheMu.RUnlock()
// 缓存无效需要从API获取
log.Println("ListVoices, 缓存未命中从API获取语音列表")
endpoint, err := c.getEndpoint(ctx)
if err != nil {
return nil, err
}
url := fmt.Sprintf(voicesEndpoint, endpoint["r"])
log.Println("ListVoices, endpoint:", endpoint)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
return nil, err
@@ -184,7 +188,7 @@ func (c *Client) ListVoices(ctx context.Context, locale string) ([]models.Voice,
// 更新缓存
c.voicesCacheMu.Lock()
c.voicesCache = voices
c.voicesCacheExpiry = time.Now().Add(24 * time.Hour) // 缓存24小时
c.voicesCacheExpiry = time.Now().Add(2 * time.Hour) // 缓存 2 小时
c.voicesCacheMu.Unlock()
// 如果指定了locale则过滤结果

View File

@@ -8,6 +8,7 @@ import (
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"log"
"net/http"
"net/url"
"strings"
@@ -15,11 +16,9 @@ import (
"unicode/utf8"
"github.com/google/uuid"
"github.com/sirupsen/logrus"
)
var (
log = logrus.New()
client = &http.Client{}
)
@@ -71,18 +70,18 @@ func GetEndpoint() (map[string]interface{}, error) {
}
headerJson, err := json.Marshal(&headers)
fmt.Printf("GetEndpoint -> url: %s, headers: %v\n", endpointURL, string(headerJson))
log.Printf("GetEndpoint -> url: %s, headers: %v\n", endpointURL, string(headerJson))
resp, err := client.Do(req)
if err != nil {
log.Error("failed to do request: ", err)
log.Println("failed to do request: ", err)
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
log.Error("failed to get endpoint, status code: ", resp.StatusCode)
log.Println("failed to get endpoint, status code: ", resp.StatusCode)
return nil, fmt.Errorf("failed to get endpoint, status code: %d", resp.StatusCode)
}
@@ -92,6 +91,7 @@ func GetEndpoint() (map[string]interface{}, error) {
return nil, err
}
log.Println("GetEndpoint <- success get endpoint result: ", result)
return result, nil
}

View File

@@ -947,7 +947,7 @@
<label for="style" class="mb-1 font-semibold text-slate-700">风格:</label>
<select id="style"
class="p-2 border border-slate-300 rounded-md bg-white/90 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition">
<option value="loading">加载<EFBFBD><EFBFBD><EFBFBD>...</option>
<option value="loading">加载...</option>
</select>
</div>
</div>