gospider 介绍
gospider 是一个golang 爬虫神器,它内置了多种爬虫模块,是golang 爬虫必备的工具包
安装
go get -u gitee.com/baixudong/gospider
gitee地址
https://gitee.com/baixudong/gospider
github地址
https://github.com/baixudong007/gospider
开始文字转语音逆向
通过抓包得到websocket 地址
注意:这个地址中有个X-ConnectionId参数,这个参数写死或者自己生成假的都可以,这个参数不重要
分析文字转语音参数
这里一个发送了三次参数,三个参数中的X-RequestId 值,这个参数写死或者自己生成假的都可以,这个参数不重要
第一个参数
Path: speech.config
X-RequestId: 890341095E354C9D9C99066349BEC419
X-Timestamp: 2023-03-05T11:54:54.557Z
Content-Type: application/json
{"context":{"system":{"name":"SpeechSDK","version":"1.19.0","build":"JavaScript","lang":"JavaScript"},"os":{"platform":"Browser/Win32","name":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.63","version":"5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.63"}}}
第二个参数
Path: synthesis.context
X-RequestId: 890341095E354C9D9C99066349BEC419
X-Timestamp: 2023-03-05T11:54:54.558Z
Content-Type: application/json
{"synthesis":{"audio":{"metadataOptions":{"bookmarkEnabled":false,"sentenceBoundaryEnabled":false,"visemeEnabled":false,"wordBoundaryEnabled":false},"outputFormat":"audio-24khz-96kbitrate-mono-mp3"},"language":{"autoDetection":false}}}
第三个参数
Path: ssml
X-RequestId: 890341095E354C9D9C99066349BEC419
X-Timestamp: 2023-03-05T11:54:54.559Z
Content-Type: application/ssml+xml
<speak xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="http://www.w3.org/2001/mstts" xmlns:emo="http://www.w3.org/2009/10/emotionml" version="1.0" xml:lang="en-US"><voice name="zh-CN-XiaoxiaoNeural"><prosody rate="0%" pitch="0%">你可将此文本替换为所需的任何文本。你可在此文本框中编写或在此处粘贴你自己的文本。
试用不同的语言和声音。改变语速和音调。你甚至可调整 SSML(语音合成标记语言),以控制文本不同部分的声音效果。单击上面的 SSML 试用一下!
请尽情使用文本转语音功能!</prosody></voice></speak>
注意: 这三个参数要以text 的形式发送到接口。参数中的值没有难度文章来源:https://www.toymoban.com/news/detail-515427.html
gospider 代码实现
package main
import (
"fmt"
"log"
"strings"
"time"
"gitee.com/baixudong/gospider/re"
"gitee.com/baixudong/gospider/requests"
"gitee.com/baixudong/gospider/tools"
"gitee.com/baixudong/gospider/websocket"
"github.com/google/uuid"
)
func createMsg(path, requestId, contentType string, con string) []byte {
txt := fmt.Sprintf("Path: %s\r\nX-RequestId: %s\r\nX-Timestamp: %s\r\nContent-Type: %s\r\n\r\n%s",
path,
requestId,
time.Now().Format("2006-01-02T15:04:05.271Z"),
contentType,
con,
)
return tools.StringToBytes(txt)
}
var quid = strings.ToUpper(re.Sub("-", "", uuid.New().String()))
func main() {
socketUrl := "wss://eastus.api.speech.microsoft.com/cognitiveservices/websocket/v1?TrafficType=AzureDemo&Authorization=bearer%20undefined&X-ConnectionId=" + strings.ToUpper(re.Sub("-", "", uuid.New().String()))
reqCli, err := requests.NewClient(nil)
if err != nil {
log.Panic(err)
}
resp, err := reqCli.Request(nil, "get", socketUrl, requests.RequestOption{
Headers: map[string]string{
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
"Cache-Control": "no-cache",
"Host": "eastus.api.speech.microsoft.com",
"Origin": "https://azure.microsoft.com",
"Pragma": "no-cache",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.26",
},
})
if err != nil {
log.Panic(err)
}
wsCli := resp.WebSocket()
if err = wsCli.Send(nil,
websocket.MessageText,
createMsg("speech.config", quid, "application/json",
tools.Any2json(map[string]any{
"context": map[string]any{
"system": map[string]string{"name": "SpeechSDK", "version": "1.19.0", "build": "JavaScript", "lang": "JavaScript"},
"os": map[string]string{"platform": "Browser/Win32", "name": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.26",
"version": "5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.26"},
},
}).Raw),
); err != nil {
log.Panic(err)
}
if err = wsCli.Send(nil, websocket.MessageText, createMsg("synthesis.context", quid, "application/json",
tools.Any2json(map[string]any{
"synthesis": map[string]any{
"audio": map[string]any{
"metadataOptions": map[string]bool{"bookmarkEnabled": false, "sentenceBoundaryEnabled": false, "visemeEnabled": false, "wordBoundaryEnabled": false},
"outputFormat": "audio-24khz-96kbitrate-mono-mp3",
},
"language": map[string]bool{"autoDetection": false},
},
}).Raw,
)); err != nil {
log.Panic(err)
}
if err = wsCli.Send(nil, websocket.MessageText, createMsg("ssml", quid, "application/ssml+xml",
`<speak xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="http://www.w3.org/2001/mstts" xmlns:emo="http://www.w3.org/2009/10/emotionml" version="1.0" xml:lang="en-US"><voice name="zh-CN-XiaoxiaoNeural"><prosody rate="0%" pitch="0%">
招标125456请尽情使用招标125456
</prosody></voice></speak>`,
)); err != nil {
log.Panic(err)
}
for {
msgType, msgCon, err := wsCli.Recv(nil)
if err != nil {
log.Panic(err)
}
switch msgType {
case websocket.MessageText:
log.Print(string(msgCon))
if strings.Contains(string(msgCon), "Path:turn.end") {
log.Print("转换结束")
break
}
case websocket.MessageBinary: //音频流
log.Print("读取音频流中")
}
}
}
现在就可以免费的使用微软的文字转语音服务了文章来源地址https://www.toymoban.com/news/detail-515427.html
到了这里,关于微软-文字转语音.语音合成--逆向爬虫实战的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!