package com.ruoyi.cms.controller.app;

import com.alibaba.nls.client.AccessToken;
import com.ruoyi.cms.handler.SpeechRecognizerAI;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * app语音Controller
 * 
 * @author lishundong
 * @date 2024-09-03
 */
@RestController
@RequestMapping("/app/speech")
@Api(tags = "移动端:用户相关")
public class AppSpeechController extends BaseController
{
    private String appKey = "4lFYn2yPsQymwGu8";
    private String id = "LTAI5t9hhSqdDHqwH3RjgyYj";
    private String secret = "ni5aW3vxrWouMwcGqJPfh9Uu56PBuv";
    private String url = System.getenv().getOrDefault("NLS_GATEWAY_URL", "wss://nls-gateway-cn-shanghai.aliyuncs.com/ws/v1");
    @ApiOperation("统计")
    @GetMapping("/getToken")
    public AjaxResult getToken()
    {
        SpeechRecognizerAI recognizerDemo = new SpeechRecognizerAI(appKey, id, secret, url);
        AccessToken accessToken = recognizerDemo.getAccessToken();
        String token = "wss://nls-gateway.cn-shanghai.aliyuncs.com/ws/v1?appkey="+appKey+"&token="+accessToken.getToken();
        return AjaxResult.success(token);
    }
}
