Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1f7fab5c0b | ||
|
|
f849a2f5ea | ||
|
|
93fd842f64 | ||
|
|
901bb4c3d1 | ||
|
|
99fd935ae9 | ||
|
|
66421eebec |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -25,4 +25,5 @@ go.work.sum
|
|||||||
# env file
|
# env file
|
||||||
.env
|
.env
|
||||||
|
|
||||||
.idea/
|
.DS_Store
|
||||||
|
.idea
|
||||||
|
|||||||
@@ -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 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
|
```yaml
|
||||||
server:
|
server:
|
||||||
|
|||||||
@@ -117,6 +117,8 @@ func (c *Client) ListVoices(ctx context.Context, locale string) ([]models.Voice,
|
|||||||
// 检查缓存是否有效
|
// 检查缓存是否有效
|
||||||
c.voicesCacheMu.RLock()
|
c.voicesCacheMu.RLock()
|
||||||
if !c.voicesCacheExpiry.IsZero() && time.Now().Before(c.voicesCacheExpiry) && len(c.voicesCache) > 0 {
|
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
|
voices := c.voicesCache
|
||||||
c.voicesCacheMu.RUnlock()
|
c.voicesCacheMu.RUnlock()
|
||||||
|
|
||||||
@@ -135,12 +137,14 @@ func (c *Client) ListVoices(ctx context.Context, locale string) ([]models.Voice,
|
|||||||
c.voicesCacheMu.RUnlock()
|
c.voicesCacheMu.RUnlock()
|
||||||
|
|
||||||
// 缓存无效,需要从API获取
|
// 缓存无效,需要从API获取
|
||||||
|
log.Println("ListVoices, 缓存未命中,从API获取语音列表")
|
||||||
endpoint, err := c.getEndpoint(ctx)
|
endpoint, err := c.getEndpoint(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
url := fmt.Sprintf(voicesEndpoint, endpoint["r"])
|
url := fmt.Sprintf(voicesEndpoint, endpoint["r"])
|
||||||
|
log.Println("ListVoices, endpoint:", endpoint)
|
||||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -184,7 +188,7 @@ func (c *Client) ListVoices(ctx context.Context, locale string) ([]models.Voice,
|
|||||||
// 更新缓存
|
// 更新缓存
|
||||||
c.voicesCacheMu.Lock()
|
c.voicesCacheMu.Lock()
|
||||||
c.voicesCache = voices
|
c.voicesCache = voices
|
||||||
c.voicesCacheExpiry = time.Now().Add(24 * time.Hour) // 缓存24小时
|
c.voicesCacheExpiry = time.Now().Add(2 * time.Hour) // 缓存 2 小时
|
||||||
c.voicesCacheMu.Unlock()
|
c.voicesCacheMu.Unlock()
|
||||||
|
|
||||||
// 如果指定了locale,则过滤结果
|
// 如果指定了locale,则过滤结果
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -15,11 +16,9 @@ import (
|
|||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
log = logrus.New()
|
|
||||||
client = &http.Client{}
|
client = &http.Client{}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -71,18 +70,18 @@ func GetEndpoint() (map[string]interface{}, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
headerJson, err := json.Marshal(&headers)
|
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)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("failed to do request: ", err)
|
log.Println("failed to do request: ", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
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)
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Println("GetEndpoint <- success get endpoint result: ", result)
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -947,7 +947,7 @@
|
|||||||
<label for="style" class="mb-1 font-semibold text-slate-700">风格:</label>
|
<label for="style" class="mb-1 font-semibold text-slate-700">风格:</label>
|
||||||
<select id="style"
|
<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">
|
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>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user