edge_tts

package
v0.0.0-...-d4675ba Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 15, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TRUSTED_CLIENT_TOKEN = "6A5AA1D4EAFF4E9FB37E23D68491D6F4"
	WSS_URL              = "wss://speech.platform.bing.com/consumer/speech/synthesize/readaloud/edge/v1?TrustedClientToken=" + TRUSTED_CLIENT_TOKEN
	VOICE_LIST_URL       = "https://speech.platform.bing.com/consumer/speech/synthesize/readaloud/voices/list?trustedclienttoken=" + TRUSTED_CLIENT_TOKEN
)

edge tts 相关接口

View Source
const CHROMIUM_FULL_VERSION = "134.0.3124.66"
View Source
const (
	PackageVersion = "0.0.1" // edge-tts-go 包版本
)

Variables

View Source
var (
	CHROMIUM_MAJOR_VERSION = strings.SplitN(CHROMIUM_FULL_VERSION, ".", 2)[0]
	SEC_MS_GEC_VERSION     = fmt.Sprintf("1-%s", CHROMIUM_FULL_VERSION)

	BASE_HEADERS = map[string]string{
		"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", CHROMIUM_MAJOR_VERSION, CHROMIUM_MAJOR_VERSION),
		"Accept-Encoding": "gzip, deflate, br",
		"Accept-Language": "en-US,en;q=0.9",
	}

	WSS_HEADERS = MergeMap(map[string]string{
		"Pragma":        "no-cache",
		"Cache-Control": "no-cache",
		"Origin":        "chrome-extension://jdiccldimpdaibmpdkjnbmckianbfold",
	}, BASE_HEADERS)

	VOICE_HEADERS = MergeMap(map[string]string{
		"Authority":        "speech.platform.bing.com",
		"Sec-CH-UA":        fmt.Sprintf(`" Not;A Brand";v="99", "Microsoft Edge";v="%s", "Chromium";v="%s"`, CHROMIUM_MAJOR_VERSION, CHROMIUM_MAJOR_VERSION),
		"Sec-CH-UA-Mobile": "?0",
		"Accept":           "*/*",
		"Sec-Fetch-Site":   "none",
		"Sec-Fetch-Mode":   "cors",
		"Sec-Fetch-Dest":   "empty",
	}, BASE_HEADERS)
)
View Source
var NoAudioReceived = errors.New("no audio received from the server")

NoAudioReceived error when no audio is received from the server

View Source
var UnexpectedResponse = errors.New("unexpected response received from the server")

UnexpectedResponse error for unexpected server responses

This hasn't happened yet, but it's possible that the server will change its response format in the future.

View Source
var UnknownResponse = errors.New("unknown response received from the server")

UnknownResponse error for unknown server responses

View Source
var WebSocketError = errors.New("WebSocket error occurred")

WebSocketError error for WebSocket errors

Functions

func AdjustClockSkew

func AdjustClockSkew(skewSeconds float64)

AdjustClockSkew 调整时钟偏差(线程安全)

func GenerateSecMSGec

func GenerateSecMSGec() string

GenerateSecMSGec 生成Sec-MS-GEC令牌

func GetUnixTimestamp

func GetUnixTimestamp() float64

GetUnixTimestamp 获取当前Unix时间戳(含时钟偏差校正)

func HandleClientResponseError

func HandleClientResponseError(resp *http.Response) error

HandleClientResponseError 处理客户端响应错误

func MergeMap

func MergeMap(m1, m2 map[string]string) map[string]string

func ParseRFC2616Date

func ParseRFC2616Date(date string) (float64, error)

ParseRFC2616Date 解析RFC 2616日期字符串

func ValidateStringParam

func ValidateStringParam(paramName, paramValue, pattern string) (string, error)

ValidateStringParam validates the given string parameter based on type and pattern.

Types

type Communicate

type Communicate struct {
	// contains filtered or unexported fields
}

Communicate is a struct representing communication with the service.

func NewCommunicate

func NewCommunicate(text string, options ...CommunicateOption) (*Communicate, error)

NewCommunicate initializes the Communicate struct.

func (*Communicate) Stream

func (c *Communicate) Stream() ([]byte, error)

type CommunicateOption

type CommunicateOption func(*Communicate) error

func SetPitch

func SetPitch(pitch string) CommunicateOption

SetPitch sets the pitch for communication.

func SetProxy

func SetProxy(proxy string) CommunicateOption

SetProxy sets the proxy for communication.

func SetRate

func SetRate(rate string) CommunicateOption

SetRate sets the rate for communication.

func SetReceiveTimeout

func SetReceiveTimeout(receiveTimeout int) CommunicateOption

SetReceiveTimeout sets the receive timeout for communication.

func SetVoice

func SetVoice(voice string) CommunicateOption

SetVoice sets the voice for communication.

func SetVolume

func SetVolume(volume string) CommunicateOption

SetVolume sets the volume for communication.

type Voice

type Voice struct {
	Name           string   `json:"Name"`
	ShortName      string   `json:"ShortName"`
	Gender         string   `json:"Gender"`
	Locale         string   `json:"Locale"`
	SuggestedCodec string   `json:"SuggestedCodec"`
	FriendlyName   string   `json:"FriendlyName"`
	Status         string   `json:"Status"`
	VoiceTag       VoiceTag `json:"VoiceTag"`
}

func ListVoices

func ListVoices(proxyURL string) ([]Voice, error)

type VoiceTag

type VoiceTag struct {
	ContentCategories  []string `json:"ContentCategories"`
	VoicePersonalities []string `json:"VoicePersonalities"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL