Skip to content

Commit 59e3e25

Browse files
author
czyt
committed
fix tts generation failed
1 parent 0506c06 commit 59e3e25

File tree

3 files changed

+47
-6
lines changed

3 files changed

+47
-6
lines changed

internal/businessConsts/constants.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
package businessConsts
22

3-
const (
4-
trustedClientToken = "6A5AA1D4EAFF4E9FB37E23D68491D6F4"
5-
EdgeWssEndpoint = "wss://speech.platform.bing.com/consumer/speech/synthesize/" + "readaloud/edge/v1?trustedClientToken=" + trustedClientToken
6-
VoiceListEndpoint = "https://speech.platform.bing.com/consumer/speech/synthesize/readaloud/voices/list?trustedclienttoken=" + trustedClientToken
3+
import (
4+
"fmt"
5+
"strings"
6+
)
7+
8+
var (
9+
BaseUrl = "speech.platform.bing.com/consumer/speech/synthesize/readaloud"
10+
TrustedClientToken = "6A5AA1D4EAFF4E9FB37E23D68491D6F4"
11+
12+
EdgeWssEndpoint = fmt.Sprintf("wss://%s/edge/v1?TrustedClientToken=%s", BaseUrl, TrustedClientToken)
13+
VoiceListEndpoint = fmt.Sprintf("https://%s/voices/list?trustedclienttoken=%s", BaseUrl, TrustedClientToken)
14+
15+
ChromiumFllVersion = "130.0.2849.68"
16+
ChromiumMajorVersion = strings.Split(ChromiumFllVersion, ".")[0]
717
)
818

919
const (

internal/communicate/communicate.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ func makeHeaders() http.Header {
153153
header.Set("Origin", "chrome-extension://jdiccldimpdaibmpdkjnbmckianbfold")
154154
header.Set("Accept-Encoding", "gzip, deflate, br")
155155
header.Set("Accept-Language", "en-US,en;q=0.9")
156-
header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36 Edg/129.0.0.0")
156+
header.Set("User-Agent", fmt.Sprintf("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/%s.0.0.0 Safari/537.36 Edg/%s.0.0.0",
157+
businessConsts.ChromiumMajorVersion,
158+
businessConsts.ChromiumMajorVersion,
159+
))
157160
return header
158161
}
159162

@@ -199,7 +202,10 @@ func (c *Communicate) stream(ctx context.Context, output chan map[string]interfa
199202
var wg sync.WaitGroup
200203

201204
for idx, text := range texts {
202-
wsURL := businessConsts.EdgeWssEndpoint + "&ConnectionId=" + generateConnectID()
205+
wsURL := businessConsts.EdgeWssEndpoint +
206+
"&Sec-MS-GEC=" + GenerateSecMsGecToken() +
207+
"&Sec-MS-GEC-Version=" + GenerateSecMsGecVersion() +
208+
"&ConnectionId=" + generateConnectID()
203209
dialer := websocket.Dialer{}
204210
setupWebSocketProxy(&dialer, c)
205211

internal/communicate/drm.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package communicate
2+
3+
import (
4+
"crypto/sha256"
5+
"fmt"
6+
"github.com/lib-x/edgetts/internal/businessConsts"
7+
"time"
8+
)
9+
10+
func GenerateSecMsGecToken() string {
11+
now := time.Now().UTC()
12+
ticks := (now.Unix() + 11644473600) * 10000000
13+
ticks = ticks - (ticks % 3_000_000_000)
14+
15+
strToHash := fmt.Sprintf("%d%s", ticks, businessConsts.TrustedClientToken)
16+
hash := sha256.New()
17+
hash.Write([]byte(strToHash))
18+
hexDig := fmt.Sprintf("%X", hash.Sum(nil))
19+
return hexDig
20+
}
21+
22+
// GenerateSecMsGecVersion Sec-MS-GEC-Version token
23+
func GenerateSecMsGecVersion() string {
24+
return fmt.Sprintf("1-%s", businessConsts.ChromiumFllVersion)
25+
}

0 commit comments

Comments
 (0)