固定值:client_credentials
发布时间:2025-06-24 17:45:13 作者:北方职教升学中心 阅读量:759
如果不懂。
获取 Access token。
public function voice() { // 请求Api $api = 'https://open.xjguoyu.cn/api/core/1.0/asr?appKey=你的appkey'; // Wav 转换base64 $audioFilePath = 'voice.wav'; // 填写您的音频文件路径 $audioData = file_get_contents($audioFilePath); $audio = base64_encode($audioData); //Base64 音频数据 $format = 'wav'; // 类型 $lang = 'ug'; // 语言 语种: cn , ug , kz , en // AccessToken $authorizationToken = $this->AccessToken(); $response = Http::withOptions([ 'verify' => false, // 禁用 SSL 验证 ])->withHeaders([ 'Content-Type' => 'application/json;charset=utf-8', 'Authorization' => 'Bearer ' .$authorizationToken, // AccessToken ])->post($api, [ 'audio' => $audio, 'format' => $format, 'lang' => $lang, ]); return $response->json(); // 返回 JSON 响应 }。
接口地址:https://open.xjguoyu.cn/api/auth/oauth/token。 请求示例: public function tts(){ // 请求Api $api = 'https://open.xjguoyu.cn/api/core/1.0/tts?appKey=你的appkey '; // appKey 在后台菜单中 我的应用->应用管理 内获取 $text = ' بۇ بولسا ئۇيغۇرچە خەت '; // 文本 $format = 'wav'; // 导出类型 $lang = 'ug'; // 语言 $speaker = 'hoshur'; // 播音员 // AccessToken $authorizationToken = $this->AccessToken(); $response = Http::withOptions([ 'verify' => false, // 禁用 SSL 验证 ])->withHeaders([ 'Content-Type' => 'application/json;charset=utf8', 'Authorization' => 'Bearer ' .$authorizationToken, // AccessToken ])->post($api, [ 'text' => $text, 'lang' => $lang, 'speaker' => $speaker, ]); $data = $response->json(); // Log::info($data); if($data['success']){ //Log::info($data['value']); } //dd($response->json()); }。目前mp3格式出现错误,请暂时使用wav。
Content-Type: 。
use Illuminate\Support\Facades\Http;use Illuminate\Support\Facades\Cache;// Access token 获取 public function AccessToken(){ // 在缓存中删除代码 // Cache::forget('guoyu_token'); // 检查Accestoken是否存在(有效) $token = Cache::get('guoyu_token'); if ($token) { // 如果accestoken已经存在,请求方式:POST。
语音识别。 | 4。的有效期。 | |
xiaojiang。
是。 | cn。mp3格式,默认为wav。 | |
xiringul。Qeyserm。 | format。,请求方式:GET。 | |
是。 | 是否必须。 |
要求PHP代码。
内获取。Access token是调用服务API的凭证,在调用服务API之前需要获取 token。
kz。 appKey 在后台菜单中。我的应用->应用管理。
speaker。
erlan。11。 xiaoli。 丝路AI平台。
说明。
丝路AI平台。
是。
application/json;charset=utf8。 语音合成。 | 客户端ID。 | audio。 | 是否必须。 | |
alice。 | ||||
目前只支持wav格式,采样16K。 | 6。 | |||
almagul。 | 是。 | format。 | ||
secret。 | ||||
grant_type。 | ||||
是。 | en。 | cn。 | ||
hoshur。 | ||||
hawagul。API网站。 | ||||
jack。 | 语言。直接返回 return $token; } else { // 如果 AccessToken 没有获取和缓存的存在 AccessToken $response = Http::withOptions(['verify' => false])->asForm()->post('https://open.xjguoyu.cn/api/auth/oauth/token', [ 'grant_type' => 'client_credentials', 'client_id' => '', 'secret' =>'',// ]); $data = $response->json(); if (!isset($data['access_token'])) { return '错误'; } // 请求数据 $access_token = $data['access_token']; // $token_type = $data['token_type']; // token 类型 Bearer $expires_in = $data['expires_in']; //有效期 // 缓存 Cache::put('guoyu_token', $access_token, $expires_in); // return $token; } }。 | 12。 接口地址:https://open.xjguoyu.cn/api/core/1.0/tts。 | 播音员列表: | 序号。 |
播音员。以下参数描述如下::
|