当前位置:网站首页>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;
}
}
}
边栏推荐
- oracle存储过程2
- 天翼云数字政府智慧数据中台通过认证
- Lao Wang said that the sixth issue of the series: PHP programmers should build their own self-confidence
- Flutter混合开发练习——Evenet&Method Channel协作加载大图
- Flutter's custompaint drawing Bezier curve chart (III)
- 1961-Check If String Is a Prefix of Array(检查字符串是否为数组前缀)
- 信创之下:国产数据库群星闪耀时
- Endeavouros installation configuration introduction!
- SAP-ABAP-SE14丢失的数据如何恢复
- TiFlash 函数下推必知必会丨十分钟成为 TiFlash Contributor
猜你喜欢

第十一届 蓝桥杯 嵌入式设计与开发项目 决赛

天翼云数字政府智慧数据中台通过认证

SAP-ABAP-BAPI_GOODSMVT_CREATE创建物料凭证bapi的各种情况如何赋值

Heavyweight live | bizdevops: the way to break the technology situation under the tide of digital transformation

Reddit产品主管:为Web3创作者准备的NFT会员实用指南

1961-Check If String Is a Prefix of Array(检查字符串是否为数组前缀)

SAP-MM-MIGO 311工厂内转移挑拨库存

Universaldependencies dependency label interpretation

Getting started with fluent Animation: inner and outer reverse ring loading animation

ffmpeg将amr格式转成mp3格式
随机推荐
TIS教程03-导出
webrtc入门:11.Kurento中使用RtpEndpoint拉取rtp流在直播中做集群
自动删除指定目录、指定时间内的日志文件
Flutter混合开发练习——Evenet&Method Channel协作加载大图
SAP-ABAP-SE14丢失的数据如何恢复
Endeavouros installation configuration introduction!
Lao Wang said that the sixth issue of the series: PHP programmers should build their own self-confidence
Difference between function pointer and pointer function
4tb production database cannot be accessed due to disk rejecting i/o to offline device failure
sql行列转换
Analysis of STM32 Hal serial port interrupt
【游戏】周瑜技巧
Correct posture of MySQL executing script
mysql 执行脚本的正确姿势
1961 check if string is a prefix of array
Flutter:剥离StatefulWidget——简化页面开发、跳转以及传值
SQL函数——将一对多关系转换成一对一关系
C language itoa() function and atoi() function explanation (integer to character c implementation)
oracle处理插入重复记录的技巧
Reddit产品主管:为Web3创作者准备的NFT会员实用指南