当前位置:网站首页>Wisdom age voice +php
Wisdom age voice +php
2022-06-22 12:43:00 【cathy1213】
Due to the company's server environment and various restrictions , We use audio recording from the front end , Upload audio from the front end to Alibaba cloud oss( Transfer the server pressure to Alibaba cloud ), Again by php The obtained audio will be graded and judged with wisdom age speech .
1. Account preparation :
Tencent cloud account secretId,secretKey
SDK Document center
download php Version of sdk
reference Example /soe/v20180724/ Example , combination API file , It's up to you “ The pronunciation data transmission interface comes with the initialization process ”
Be careful : The audio adoption rate must be 16k Sampling rate 16bit Bit deep mono
Here are tp5.1 An example of
<?php
namespace app\api\controller;
use TencentCloud\Soe\V20180724\Models\TransmitOralProcessWithInitRequest;
use TencentCloud\Soe\V20180724\SoeClient;
use TencentCloud\Soe\V20180724\Models\InitOralProcess;
use TencentCloud\Common\Exception\TencentCloudSDKException;
use TencentCloud\Common\Credential;
use TencentCloud\Common\Profile\ClientProfile;
use TencentCloud\Common\Profile\HttpProfile;
use think\facade\Request;
class Api{
public function __construct()
{
require_once '../extend/tencentcloud-sdk-php-master/TCloudAutoLoader.php';
}
public function test(){
$this->init_index(Request::param('text'),Request::param('url'));
}
public function init_index($text='',$url=''){ // Identifying text , Speech recognition
try{
// Instantiate a certificate object , To join, you need to transfer it to Tencent cloud account secretId,secretKey
$cred = new Credential("secretId","secretKey");
// Instantiate a http Options , Optional , There are no special requirements to skip
$httpProfile = new HttpProfile();
$httpProfile->setReqMethod("POST"); // post request ( The default is post request )
$httpProfile->setReqTimeout(30); // Request timeout , The unit is in seconds ( Default 60 second )
$httpProfile->setEndpoint("soe.tencentcloudapi.com"); // Specify the domain name of the access region ( The default is nearest access )
// Instantiate a client Options , Optional , There are no special requirements to skip
$clientProfile = new ClientProfile();
$clientProfile->setSignMethod("TC3-HMAC-SHA256"); // Specify signature algorithm ( The default is HmacSHA256)
$clientProfile->setHttpProfile($httpProfile);
$client = new SoeClient($cred, "", $clientProfile);
$str = base64_encode(file_get_contents($url));
// Instantiate a ecc Instance information query request object , Each interface will correspond to a request object .
$req = new TransmitOralProcessWithInitRequest();
$sessionid = rand(100000,999999);
$req->SessionId = "stress_test_".$sessionid; // Unique identification of voice segment , One complete voice, one SessionId.
$req->VoiceFileType = 3; // Voice file type 1:raw, 2:wav, 3:mp3 The three formats currently only support 16k Sampling rate 16bit Encode mono , If there is any inconsistency, it may lead to inaccurate or failed evaluation
$req->SeqId = 1; // Serial number of the streaming packet , from 1 Start
$req->VoiceEncodeType = 1; // Speech coding type 1:pcm.
$req->IsEnd = 1; // Whether the transmission is completed , if 0 It means not finished , if 1 Then the transmission is completed and the evaluation starts , It doesn't make sense in non streaming mode .
$req->TextMode = 0; // Enter text mode ,0: Plain text ,1: Phoneme structure text .
$req->UserVoiceData = $str;
$req->RefText = $text; // The text corresponding to the evaluated voice
$req->WorkMode = 1; // Voice input mode ,0: Streaming shard ,1: Non-streaming one-time assessment
$req->EvalMode = 3; // The evaluation mode ,0: Word patterns 1: The sentence pattern 2: paragraph mode 3: Free talk mode
$req->ScoreCoeff = 2; // Evaluation severity index , The value is [1.0 - 4.0] Range of floating point Numbers , Used to smooth scores for different ages ,1.0 For the younger age group ,4.0 Is the highest age group
$resp = $client->TransmitOralProcessWithInit($req);
// Output json Format string package
return $resp->toJsonString();
}catch (TencentCloudSDKException $e) {
return $e;
}
}
}
边栏推荐
- Sap-abap- how to open a local file
- SAP-ABAP-BAPI_GOODSMVT_CREATE创建物料凭证bapi的各种情况如何赋值
- 什么是C语言结构体字节对齐,为什么要对齐?
- TiFlash 函数下推必知必会丨十分钟成为 TiFlash Contributor
- Final of the 11th Blue Bridge Cup embedded design and development project
- Parallels Desktop 17.1.4pd virtual machine
- Flutter之CustomPaint 绘制贝塞尔曲线图表(三)
- SAP-SPRO-配置如何显示对应的T-CODE
- SequoiaDB分布式数据库2022.5月刊
- SQl、Oracle剔除重复记录的语句
猜你喜欢
随机推荐
oracle存储过程2
TIS教程03-导出
Universaldependencies dependency label interpretation
View the GStreamer plug-in
Flutter——实现网易云音乐的Tabbar切换效果
Chown failed to change the owner and group of the directory
Jushan database was invited to attend Kunpeng developers' annual event 2022 to jointly build a domestic digital base
Analysis of STM32 Hal serial port interrupt
uboot do_ Load function analysis
[QT] qfileinfo get the components of the file name
Terraform的vpc网络自动化配置解决方案
Flutter mixed development exercise - large picture of collaborative loading of ever & method channel
SAP-ABAP-如何用WEBAPI的方式调用外部接口
TIS教程04-客户端
【mysql】用sql求中位数
Lao Wang said that the sixth issue of the series: PHP programmers should build their own self-confidence
银行支付接口开发之子账户
Repair flutter_ webview_ The problem of web layer residue when the plugin slides out of the page
Correct posture of MySQL executing script
repo解析的xml文件








