php sdk 百度(API)智能语音识别

版权声明:本文为勇哥原创文章,转载请注明出处哦!!! https://blog.csdn.net/woshihaiyong168/article/details/78816072

实现效果:


client.php    上传一段test.wav(就是一段录音)     识别该录音的文字

步骤1:百度开发平台注册成为开发者

http://yuyin.baidu.com

步骤2:建立一个应用   并下载php sdk



4、根据PHP sdk文档   http://ai.baidu.com/docs/#/ASR-Online-PHP-SDK/top

因为是调用接口测试所以在转换音频格式使用的是格式工厂,如果项目需要可使用代码自动转换(自行百度)

这里写图片描述

这里写图片描述

这里写图片描述

然后进行确认转换得出来的格式再进行测试即可,谢谢~


将文档中 新建AipSpeech  改成新建 client.php (这边随意想什么名字都行)


打印  返回的参数就OK了 下面贴出client代码:

<?php  

require_once 'AipSpeech.php';

// 你的 APPID AK SK
const APP_ID = '10533442';
const API_KEY = 'eb8vDMwPyec1DGxecYQRzEjz';
const SECRET_KEY = '56ac673eafc3a65f49dd37d8dd8f27e8';

$client = new AipSpeech(APP_ID, API_KEY, SECRET_KEY);
// 识别本地文件
$li = $client->asr(file_get_contents('./test.wav'), 'wav', 16000, array(
    'lan' => 'zh',
));

interface Msg{
	function getMsg();
}

class Result implements Msg{
	protected $res = null;
	protected function __construct($re){
		$this->res = $re;
	}
    public  function getMsg(){}
}
class Success extends Result{
	public function __construct($re){
		parent::__construct($re);
	}
	public function getMsg(){
		if ($this->res['err_msg'] == 'success.') {
			// var_dump($this->res);exit;
			echo  $this->res['result'][0];
		}
	}
}

$tmp = new Success($li);
$tmp->getMsg();




?>







猜你喜欢

转载自blog.csdn.net/woshihaiyong168/article/details/78816072