Skip to content

Commit

Permalink
fixed tts playback mod
Browse files Browse the repository at this point in the history
  • Loading branch information
navrotskyj committed Jun 15, 2020
1 parent f3b9b79 commit a4f5ebf
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions src/call/tts.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func ttsDefault(c *Call, props map[string]interface{}, text string) error {
}
}

return ttsToPlayback(c, props, query, "default")
return ttsToPlayback(c, props, query, "default", nil)
}

func ttsMicrosoft(c *Call, props map[string]interface{}, text string) error {
Expand Down Expand Up @@ -89,14 +89,19 @@ func ttsMicrosoft(c *Call, props map[string]interface{}, text string) error {
query += "&region=" + tmp
}

return ttsToPlayback(c, props, query, "microsoft")
return ttsToPlayback(c, props, query, "microsoft", nil)
}

var mp3Mod = ".mp3"
var wavMod = ".wav"

func ttsGoogle(c *Call, props map[string]interface{}, text string) error {
query := "text=" + text
var ok bool
var tmp string

var format *string

if _, ok = props["voice"]; ok {
if _, ok = props["voice"].(map[string]interface{}); ok {
voice := props["voice"].(map[string]interface{})
Expand All @@ -113,6 +118,13 @@ func ttsGoogle(c *Call, props map[string]interface{}, text string) error {

if tmp = getStringValueFromMap("audioEncoding", voice, ""); tmp != "" {
query += "&audioEncoding=" + tmp

switch tmp {
case "OGG_OPUS", "MP3":
format = &mp3Mod
default:
format = &wavMod
}
}
if tmp = getStringValueFromMap("sampleRateHertz", voice, ""); tmp != "" {
query += "&sampleRateHertz=" + tmp
Expand All @@ -137,7 +149,7 @@ func ttsGoogle(c *Call, props map[string]interface{}, text string) error {
query += "&textType=" + tmp
}

return ttsToPlayback(c, props, query, "google")
return ttsToPlayback(c, props, query, "google", format)
}

func ttsPolly(c *Call, props map[string]interface{}, text string) error {
Expand All @@ -152,13 +164,18 @@ func ttsPolly(c *Call, props map[string]interface{}, text string) error {
query += "&textType=" + tmp
}

return ttsToPlayback(c, props, query, "polly")
return ttsToPlayback(c, props, query, "polly", nil)
}

func ttsGetCodecSettings(writeRateVar string) (rate string, format string) {
func ttsGetCodecSettings(writeRateVar string, defFormat *string) (rate string, format string) {
rate = "8000"
format = "mp3"

if defFormat != nil {
format = *defFormat
return
}

if writeRateVar != "" {
if i, err := strconv.Atoi(writeRateVar); err == nil {
if i == 8000 || i == 16000 {
Expand All @@ -179,10 +196,10 @@ func ttsAddCredential(key, token string) string {
return ""
}

func ttsToPlayback(c *Call, props map[string]interface{}, query, provider string) error {
func ttsToPlayback(c *Call, props map[string]interface{}, query, provider string, defFormat *string) error {
var tmp string
var ok bool
rate, format := ttsGetCodecSettings(c.GetVariable("write_rate"))
rate, format := ttsGetCodecSettings(c.GetVariable("write_rate"), defFormat)

if format == "mp3" {
tmp = "shout"
Expand Down

0 comments on commit a4f5ebf

Please sign in to comment.