@@ -28,7 +28,7 @@ import (
2828
2929const (
3030 ssmlHeaderTemplate = "X-RequestId:%s\r \n Content-Type:application/ssml+xml\r \n X-Timestamp:%sZ\r \n Path:ssml\r \n \r \n "
31- ssmlTemplate = "<speak version='1.0' xmlns='http://www.w3.org/2001/10/synthesis' xml:lang='en-US'><voice name='%s'><prosody pitch='+0Hz ' rate='%s' volume='%s'>%s</prosody></voice></speak>"
31+ ssmlTemplate = "<speak version='1.0' xmlns='http://www.w3.org/2001/10/synthesis' xml:lang='en-US'><voice name='%s'><prosody pitch='%s ' rate='%s' volume='%s'>%s</prosody></voice></speak>"
3232)
3333
3434var (
@@ -46,26 +46,27 @@ func init() {
4646type Communicate struct {
4747 text string
4848 voice string
49- voiceLanguageRegion string
49+ pitch string
5050 rate string
5151 volume string
52+ voiceLanguageRegion string
5253
5354 httpProxy string
5455 socket5Proxy string
5556 socket5ProxyUser string
5657 socket5ProxyPass string
57- op chan map [string ]interface {}
5858
5959 audioDataIndex int
6060 prevIdx int
6161 shiftTime int
6262 finalUtterance map [int ]int
63+ op chan map [string ]interface {}
6364}
6465
6566type textEntry struct {
6667 Text string `json:"text"`
67- Length int64 `json:"Length"`
6868 BoundaryType string `json:"BoundaryType"`
69+ Length int64 `json:"Length"`
6970}
7071type dataEntry struct {
7172 Offset int `json:"Offset"`
@@ -112,6 +113,7 @@ func NewCommunicate(text string, opt *communicateOption.CommunicateOption) (*Com
112113 }
113114 return & Communicate {
114115 text : text ,
116+ pitch : opt .Pitch ,
115117 voice : opt .Voice ,
116118 voiceLanguageRegion : opt .VoiceLangRegion ,
117119 rate : opt .Rate ,
@@ -171,7 +173,7 @@ func makeHeaders() http.Header {
171173func (c * Communicate ) stream () (<- chan map [string ]interface {}, error ) {
172174 texts := splitTextByByteLength (
173175 escape (removeIncompatibleCharacters (c .text )),
174- calculateMaxMessageSize (c .voice , c .rate , c .volume ),
176+ calculateMaxMessageSize (c .pitch , c . voice , c .rate , c .volume ),
175177 )
176178 c .audioDataIndex = len (texts )
177179
@@ -234,7 +236,7 @@ func (c *Communicate) sendSSML(conn *websocket.Conn, currentTime string, text []
234236 ssmlHeadersAppendExtraData (
235237 generateConnectID (),
236238 currentTime ,
237- makeSsml (string (text ), c .voice , c .rate , c .volume ),
239+ makeSsml (string (text ), c .pitch , c . voice , c .rate , c .volume ),
238240 ),
239241 ))
240242}
@@ -474,10 +476,11 @@ func splitTextByByteLength(text string, byteLength int) [][]byte {
474476 return result
475477}
476478
477- func makeSsml (text string , voice string , rate string , volume string ) string {
479+ func makeSsml (text string , pitch , voice string , rate string , volume string ) string {
478480 ssml := fmt .Sprintf (
479481 ssmlTemplate ,
480482 voice ,
483+ pitch ,
481484 rate ,
482485 volume ,
483486 text )
@@ -500,9 +503,9 @@ func ssmlHeadersAppendExtraData(requestID string, timestamp string, ssml string)
500503 return headers + ssml
501504}
502505
503- func calculateMaxMessageSize (voice string , rate string , volume string ) int {
506+ func calculateMaxMessageSize (pitch , voice string , rate string , volume string ) int {
504507 websocketMaxSize := 1 << 16
505- overheadPerMessage := len (ssmlHeadersAppendExtraData (generateConnectID (), currentTimeInMST (), makeSsml ("" , voice , rate , volume ))) + 50
508+ overheadPerMessage := len (ssmlHeadersAppendExtraData (generateConnectID (), currentTimeInMST (), makeSsml ("" , pitch , voice , rate , volume ))) + 50
506509 return websocketMaxSize - overheadPerMessage
507510}
508511
0 commit comments