|
@@ -5,8 +5,6 @@ import ( |
|
@@ -5,8 +5,6 @@ import ( |
5
|
"context"
|
5
|
"context"
|
6
|
"encoding/json"
|
6
|
"encoding/json"
|
7
|
"fmt"
|
7
|
"fmt"
|
8
|
- "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
|
|
|
9
|
- "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
|
|
|
10
|
nls "github.com/aliyun/alibabacloud-nls-go-sdk"
|
8
|
nls "github.com/aliyun/alibabacloud-nls-go-sdk"
|
11
|
"github.com/google/uuid"
|
9
|
"github.com/google/uuid"
|
12
|
"github.com/zeromicro/go-zero/core/logx"
|
10
|
"github.com/zeromicro/go-zero/core/logx"
|
|
@@ -35,7 +33,7 @@ func NewCommonTextToSpeechLogic(ctx context.Context, svcCtx *svc.ServiceContext) |
|
@@ -35,7 +33,7 @@ func NewCommonTextToSpeechLogic(ctx context.Context, svcCtx *svc.ServiceContext) |
35
|
}
|
33
|
}
|
36
|
|
34
|
|
37
|
func (l *CommonTextToSpeechLogic) CommonTextToSpeech(req *types.TextToSpeechRequest) (resp *types.TextToSpeechResponse, err error) {
|
35
|
func (l *CommonTextToSpeechLogic) CommonTextToSpeech(req *types.TextToSpeechRequest) (resp *types.TextToSpeechResponse, err error) {
|
38
|
- token, err := l.getToken1()
|
36
|
+ token, err := l.getToken()
|
39
|
if err != nil {
|
37
|
if err != nil {
|
40
|
return nil, xerr.NewErrMsgErr("授权失败", err)
|
38
|
return nil, xerr.NewErrMsgErr("授权失败", err)
|
41
|
}
|
39
|
}
|
|
@@ -52,28 +50,43 @@ func (l *CommonTextToSpeechLogic) CommonTextToSpeech(req *types.TextToSpeechRequ |
|
@@ -52,28 +50,43 @@ func (l *CommonTextToSpeechLogic) CommonTextToSpeech(req *types.TextToSpeechRequ |
52
|
return
|
50
|
return
|
53
|
}
|
51
|
}
|
54
|
|
52
|
|
55
|
-func (l *CommonTextToSpeechLogic) getToken() (string, error) {
|
|
|
56
|
- client, err := sdk.NewClientWithAccessKey(l.svcCtx.Config.TTS.ReginID, l.svcCtx.Config.TTS.AccessKeyID, l.svcCtx.Config.TTS.AccessKeySecret)
|
|
|
57
|
- if err != nil {
|
|
|
58
|
- return "", xerr.NewErrMsgErr("授权失败", err)
|
53
|
+type TokenResult struct {
|
|
|
54
|
+ ErrMsg string
|
|
|
55
|
+ Token struct {
|
|
|
56
|
+ UserId string
|
|
|
57
|
+ Id string
|
|
|
58
|
+ ExpireTime int64
|
59
|
}
|
59
|
}
|
60
|
- request := requests.NewCommonRequest()
|
|
|
61
|
- request.Method = "POST"
|
|
|
62
|
- request.Domain = l.svcCtx.Config.TTS.Domain //"nlsmeta.ap-southeast-1.aliyuncs.com"
|
|
|
63
|
- request.ApiName = "CreateToken"
|
|
|
64
|
- request.Version = "2019-02-28"
|
|
|
65
|
- response, err := client.ProcessCommonRequest(request)
|
60
|
+}
|
66
|
|
61
|
|
67
|
- if err != nil {
|
|
|
68
|
- return "", xerr.NewErrMsgErr("授权失败", err)
|
|
|
69
|
- }
|
|
|
70
|
- token := response.GetHttpContentString()
|
|
|
71
|
- return token, nil
|
62
|
+func (l *CommonTextToSpeechLogic) getToken() (string, error) {
|
|
|
63
|
+ //client, err := sdk.NewClientWithAccessKey(l.svcCtx.Config.TTS.ReginID, l.svcCtx.Config.TTS.AccessKeyID, l.svcCtx.Config.TTS.AccessKeySecret)
|
|
|
64
|
+ //if err != nil {
|
|
|
65
|
+ // return "", xerr.NewErrMsgErr("授权失败", err)
|
|
|
66
|
+ //}
|
|
|
67
|
+ //request := requests.NewCommonRequest()
|
|
|
68
|
+ //request.Method = "POST"
|
|
|
69
|
+ //request.Domain = l.svcCtx.Config.TTS.Domain //"nlsmeta.ap-southeast-1.aliyuncs.com"
|
|
|
70
|
+ //request.ApiName = "CreateToken"
|
|
|
71
|
+ //request.Version = "2019-07-17" //"2019-02-28"
|
|
|
72
|
+ //response, err := client.ProcessCommonRequest(request)
|
|
|
73
|
+ //
|
|
|
74
|
+ //if err != nil {
|
|
|
75
|
+ // return "", xerr.NewErrMsgErr("授权失败", err)
|
|
|
76
|
+ //}
|
|
|
77
|
+ //logx.Debug(response.GetHttpContentString())
|
|
|
78
|
+ //var tr TokenResult
|
|
|
79
|
+ //err = json.Unmarshal([]byte(response.GetHttpContentString()), &tr)
|
|
|
80
|
+ //if err != nil {
|
|
|
81
|
+ // return "", xerr.NewErrMsgErr("授权解析失败", err)
|
|
|
82
|
+ //}
|
|
|
83
|
+ //return tr.Token.Id, nil
|
|
|
84
|
+ return "d5868e2b5d644136add22c8a0b020435", nil
|
72
|
}
|
85
|
}
|
73
|
|
86
|
|
74
|
func (l *CommonTextToSpeechLogic) getToken1() (string, error) {
|
87
|
func (l *CommonTextToSpeechLogic) getToken1() (string, error) {
|
75
|
tts := l.svcCtx.Config.TTS
|
88
|
tts := l.svcCtx.Config.TTS
|
76
|
- client, err := nls.GetToken(tts.ReginID, tts.Domain, tts.AccessKeyID, tts.AccessKeySecret, "2019-02-28")
|
89
|
+ client, err := nls.GetToken(tts.ReginID, tts.Domain, tts.AccessKeyID, tts.AccessKeySecret, "2019-07-17")
|
77
|
if err != nil {
|
90
|
if err != nil {
|
78
|
return "", xerr.NewErrMsgErr("授权失败", err)
|
91
|
return "", xerr.NewErrMsgErr("授权失败", err)
|
79
|
}
|
92
|
}
|
|
@@ -91,7 +104,7 @@ func (l *CommonTextToSpeechLogic) processPOSTRequest(token string, text string, |
|
@@ -91,7 +104,7 @@ func (l *CommonTextToSpeechLogic) processPOSTRequest(token string, text string, |
91
|
* 5.设置可选请求参数:voice、volume、speech_rate、pitch_rate
|
104
|
* 5.设置可选请求参数:voice、volume、speech_rate、pitch_rate
|
92
|
*/
|
105
|
*/
|
93
|
ttsConfig := l.svcCtx.Config.TTS
|
106
|
ttsConfig := l.svcCtx.Config.TTS
|
94
|
- var url string = fmt.Sprintf("https://%s/stream/v1/tts", "nls-gateway-ap-southeast-1.aliyuncs.com")
|
107
|
+ var url string = fmt.Sprintf("https://%s/stream/v1/tts", "nls-gateway-cn-shanghai.aliyuncs.com") //"nls-gateway-ap-southeast-1.aliyuncs.com")
|
95
|
bodyContent := make(map[string]interface{})
|
108
|
bodyContent := make(map[string]interface{})
|
96
|
bodyContent["appkey"] = ttsConfig.AppKey
|
109
|
bodyContent["appkey"] = ttsConfig.AppKey
|
97
|
bodyContent["text"] = text
|
110
|
bodyContent["text"] = text
|
|
@@ -139,3 +152,5 @@ func (l *CommonTextToSpeechLogic) processPOSTRequest(token string, text string, |
|
@@ -139,3 +152,5 @@ func (l *CommonTextToSpeechLogic) processPOSTRequest(token string, text string, |
139
|
}
|
152
|
}
|
140
|
return nil
|
153
|
return nil
|
141
|
}
|
154
|
}
|
|
|
155
|
+
|
|
|
156
|
+// http://127.0.0.1:8081/v1/file/ff9d4ab6-f095-11ee-b153-50ebf677cbf1.wav |