@@ -3,6 +3,7 @@ package communicate
33import (
44 "bytes"
55 "context"
6+ "crypto/tls"
67 "encoding/binary"
78 "encoding/json"
89 "fmt"
@@ -44,23 +45,14 @@ func init() {
4445}
4546
4647type Communicate struct {
47- text string
48- voice string
49- pitch string
50- rate string
51- volume string
52- voiceLanguageRegion string
53-
54- httpProxy string
55- socket5Proxy string
56- socket5ProxyUser string
57- socket5ProxyPass string
48+ text string
5849
5950 audioDataIndex int
6051 prevIdx int
6152 shiftTime int
6253 finalUtterance map [int ]int
6354 op chan map [string ]interface {}
55+ opt * communicateOption.CommunicateOption
6456}
6557
6658type textEntry struct {
@@ -112,16 +104,8 @@ func NewCommunicate(text string, opt *communicateOption.CommunicateOption) (*Com
112104 return nil , err
113105 }
114106 return & Communicate {
115- text : text ,
116- pitch : opt .Pitch ,
117- voice : opt .Voice ,
118- voiceLanguageRegion : opt .VoiceLangRegion ,
119- rate : opt .Rate ,
120- volume : opt .Volume ,
121- httpProxy : opt .HttpProxy ,
122- socket5Proxy : opt .Socket5Proxy ,
123- socket5ProxyUser : opt .Socket5ProxyUser ,
124- socket5ProxyPass : opt .Socket5ProxyPass ,
107+ text : text ,
108+ opt : opt ,
125109 }, nil
126110}
127111
@@ -173,7 +157,7 @@ func makeHeaders() http.Header {
173157func (c * Communicate ) stream () (<- chan map [string ]interface {}, error ) {
174158 texts := splitTextByByteLength (
175159 escape (removeIncompatibleCharacters (c .text )),
176- calculateMaxMessageSize (c .pitch , c .voice , c .rate , c .volume ),
160+ calculateMaxMessageSize (c .opt . Pitch , c .opt . Voice , c .opt . Rate , c .opt . Volume ),
177161 )
178162 c .audioDataIndex = len (texts )
179163
@@ -236,7 +220,7 @@ func (c *Communicate) sendSSML(conn *websocket.Conn, currentTime string, text []
236220 ssmlHeadersAppendExtraData (
237221 generateConnectID (),
238222 currentTime ,
239- makeSsml (string (text ), c .pitch , c .voice , c .rate , c .volume ),
223+ makeSsml (string (text ), c .opt . Pitch , c .opt . Voice , c .opt . Rate , c .opt . Volume ),
240224 ),
241225 ))
242226}
@@ -386,18 +370,21 @@ func sumWithMap(idx int, m map[int]int) int {
386370}
387371
388372func setupWebSocketProxy (dialer * websocket.Dialer , c * Communicate ) {
389- if c .httpProxy != "" {
390- proxyUrl , _ := url .Parse (c .httpProxy )
373+ if c .opt . HttpProxy != "" {
374+ proxyUrl , _ := url .Parse (c .opt . HttpProxy )
391375 dialer .Proxy = http .ProxyURL (proxyUrl )
392376 }
393- if c .socket5Proxy != "" {
394- auth := & proxy.Auth {User : c .socket5ProxyUser , Password : c .socket5ProxyPass }
395- socket5ProxyDialer , _ := proxy .SOCKS5 ("tcp" , c .socket5Proxy , auth , proxy .Direct )
377+ if c .opt . Socket5Proxy != "" {
378+ auth := & proxy.Auth {User : c .opt . Socket5ProxyUser , Password : c .opt . Socket5ProxyPass }
379+ socket5ProxyDialer , _ := proxy .SOCKS5 ("tcp" , c .opt . Socket5Proxy , auth , proxy .Direct )
396380 dialContext := func (ctx context.Context , network , address string ) (net.Conn , error ) {
397381 return socket5ProxyDialer .Dial (network , address )
398382 }
399383 dialer .NetDialContext = dialContext
400384 }
385+ if c .opt .IgnoreSSL {
386+ dialer .TLSClientConfig = & tls.Config {InsecureSkipVerify : true }
387+ }
401388}
402389
403390func getMetaHubFrom (data []byte ) (* metaHub , error ) {
0 commit comments