本功能基於騰訊雲SDK3.0開發,要求PHP版本5.6.33及其以上。
參考文檔:
騰訊雲官方文檔:cloud.tencent.com/document/sd…
騰訊雲智聆口語評測文檔:cloud.tencent.com/document/ap…
騰訊雲智聆口語評測(Smart Oral Evaluation)英語口語評測服務,是基於英語口語類教育培訓場景和騰訊雲的語音處理技術,應用特征提取、聲學模型和語音識別算法,為兒童和成人提供高准確度的英語口語發音評測。支持單詞和句子模式的評測,多維度反饋口語表現。支持單詞和句子評測模式,可廣泛應用於英語口語類教學應用中。
本接口為語音和文本的比對,結果返回一個分值
<?php
/**
* Created by PhpStorm.
* User: Shu_Q_Gang
* Date: 2018/10/23
* Time: 15:33
*/
namespace tencent;
use TencentCloud\Common\Credential;
use TencentCloud\Common\Profile\ClientProfile;
use TencentCloud\Common\Profile\HttpProfile;
use TencentCloud\Common\Exception\TencentCloudSDKException;
use TencentCloud\Soe\V20180724\SoeClient;
use TencentCloud\Soe\V20180724\Models\TransmitOralProcessWithInitRequest;
class OralAssessment
{
/**
* @var string
* 密鑰 申請地址:https://console.cloud.tencent.com/cam/capi
*/
protected $SecretId = '**********'; protected $SecretKey = '***********'; /** * @var string * 地區 */ public $Region = "ap-beijing"; /** * @var string * 流式數據包的序號,從1開始,當IsEnd字段為1后后續序號無意義,當IsLongLifeSession不為1且為非流式模式時無意義。 */ public $SeqId = 1; /** * @var string * 是否傳輸完畢標志,若為0表示未完畢,若為1則傳輸完畢開始評估,非流式模式下無意義。 */ public $IsEnd = 1; /** * @var string * 語音文件類型 1: raw, 2: wav, 3: mp3, 4: speex (語言文件格式目前僅支持 16k 采樣率 16bit 編碼單聲道,如有不一致可能導致評估不准確或失敗)。 */ public $VoiceFileType = 2; /** * @var string * 語音編碼類型 1:pcm。 */ public $VoiceEncodeType = 1; /** * @var string * 語音輸入模式,0:流式分片,1:非流式一次性評估 */ public $WorkMode = 1; /** * @var string * 評估模式,0:詞模式(中文評測模式下為文字模式),1:句子模式,2:段落模式,3:自由說模式,當為詞模式評估時,能夠提供每個音節的評估信息,當為句子模式時,能夠提供完整度和流利度信息,4:單詞糾錯模式:能夠對單詞和句子中的讀錯讀音進行糾正,給出參考正確讀音。 */ public $EvalMode = 1; /** * @var string * 評價苛刻指數,取值為[1.0 - 4.0]范圍內的浮點數,用於平滑不同年齡段的分數,1.0為小年齡段,4.0為最高年齡段 */ public $ScoreCoeff = 1.0; /* * 發音數據傳輸接口附帶初始化過程 * $UserVoiceData 要測試的錄音 bese64 位格式 * $SessionId 標識id 時間戳即可 只能是字符串類型 * $RefText 要比對的文字 */ public function TransmitOralProcessWithInit($UserVoiceData,$SessionId,$RefText){ $cred = new Credential($this->SecretId, $this->SecretKey); $httpProfile = new HttpProfile(); $httpProfile->setEndpoint("soe.tencentcloudapi.com"); $clientProfile = new ClientProfile(); $clientProfile->setHttpProfile($httpProfile); $client = new SoeClient($cred, $this->Region, $clientProfile); $req = new TransmitOralProcessWithInitRequest(); $params['SeqId'] = $this->SeqId; $params['IsEnd'] = $this->IsEnd; $params['VoiceFileType'] = $this->VoiceFileType; $params['VoiceEncodeType'] = $this->VoiceEncodeType; $params['UserVoiceData'] = $UserVoiceData; $params['SessionId'] = $SessionId; $params['RefText'] = $RefText; $params['WorkMode'] = $this->WorkMode; $params['EvalMode'] = $this->EvalMode; $params['ScoreCoeff'] = $this->ScoreCoeff; $req->fromJsonString(json_encode($params)); $resp = $client->TransmitOralProcessWithInit($req); return json_decode($resp->toJsonString(),true); } }