修改nls、微信授权地址,通过修改状态来控制测试和正式
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package com.ruoyi.cms.handler;
|
||||
|
||||
import com.alibaba.nls.client.protocol.asr.SpeechRecognizer;
|
||||
import com.ruoyi.cms.util.AliyunNlsUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.websocket.*;
|
||||
@@ -20,7 +20,7 @@ public class SpeechRecognitionWebSocketHandler {
|
||||
String appKey = "4lFYn2yPsQymwGu8";
|
||||
String id = "LTAI5t9hhSqdDHqwH3RjgyYj";
|
||||
String secret = "ni5aW3vxrWouMwcGqJPfh9Uu56PBuv";
|
||||
String url = System.getenv().getOrDefault("NLS_GATEWAY_URL", "wss://nls-gateway-cn-shanghai.aliyuncs.com/ws/v1");
|
||||
String url = System.getenv().getOrDefault("NLS_GATEWAY_URL", AliyunNlsUtils.getNlsUrl()+"/ws/v1/");
|
||||
recognizerDemo = new SpeechRecognizerAI(appKey, id, secret, url);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.alibaba.nls.client.protocol.SampleRateEnum;
|
||||
import com.alibaba.nls.client.protocol.asr.SpeechRecognizer;
|
||||
import com.alibaba.nls.client.protocol.asr.SpeechRecognizerListener;
|
||||
import com.alibaba.nls.client.protocol.asr.SpeechRecognizerResponse;
|
||||
import com.ruoyi.cms.util.AliyunNlsUtils;
|
||||
import lombok.Data;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -26,7 +27,12 @@ public class SpeechRecognizerAI {
|
||||
// 获取 AccessToken
|
||||
accessToken = new AccessToken(id, secret);
|
||||
try {
|
||||
accessToken.apply(); // 申请 Token
|
||||
if(AliyunNlsUtils.USE_TEST_ENV){
|
||||
accessToken.apply(); // 申请 Token
|
||||
}else{
|
||||
AliyunNlsTokenUtil.generateToken(id, secret, this.accessToken);
|
||||
}
|
||||
//accessToken.apply(); // 申请 Token
|
||||
logger.info("Token: {}, Expire Time: {}", accessToken.getToken(), accessToken.getExpireTime());
|
||||
|
||||
// 初始化 NlsClient
|
||||
@@ -35,7 +41,7 @@ public class SpeechRecognizerAI {
|
||||
} else {
|
||||
this.client = new NlsClient(url, accessToken.getToken()); // 使用自定义服务地址
|
||||
}
|
||||
} catch (IOException e) {
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed to initialize NlsClient: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.alibaba.nls.client.protocol.SampleRateEnum;
|
||||
import com.alibaba.nls.client.protocol.tts.SpeechSynthesizer;
|
||||
import com.alibaba.nls.client.protocol.tts.SpeechSynthesizerListener;
|
||||
import com.alibaba.nls.client.protocol.tts.SpeechSynthesizerResponse;
|
||||
import com.ruoyi.cms.util.AliyunNlsUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -20,18 +21,23 @@ import java.nio.ByteBuffer;
|
||||
@ServerEndpoint("/speech-synthesis")
|
||||
public class SpeechSynthesisWebSocketHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(SpeechSynthesisWebSocketHandler.class);
|
||||
|
||||
|
||||
private NlsClient client;
|
||||
private String appKey = "mtA2pwmvCeefHT3Y";
|
||||
private String accessKeyId = "LTAI5tRBahK93vPNF1JDVEPA";
|
||||
private String accessKeySecret = "x95OWb4cV6ccQVtbEJ2Gxm2Uwl2thJ";
|
||||
private String url = "wss://nls-gateway-cn-shanghai.aliyuncs.com/ws/v1";
|
||||
private String url = AliyunNlsUtils.getNlsUrl()+"/ws/v1/";
|
||||
|
||||
public SpeechSynthesisWebSocketHandler() {
|
||||
// Initialize NLS client with token
|
||||
AccessToken accessToken = new AccessToken(accessKeyId, accessKeySecret);
|
||||
try {
|
||||
accessToken.apply();
|
||||
if(AliyunNlsUtils.USE_TEST_ENV){
|
||||
accessToken.apply();
|
||||
}else{
|
||||
AliyunNlsTokenUtil.generateToken(accessKeyId, accessKeySecret, accessToken);
|
||||
}
|
||||
//accessToken.apply();
|
||||
String token = accessToken.getToken();
|
||||
if(url.isEmpty()) {
|
||||
this.client = new NlsClient(token);
|
||||
|
||||
Reference in New Issue
Block a user