基本信息
源码名称:百度中文语音转英文语音
源码大小:0.29M
文件格式:.zip
开发语言:PHP
更新时间:2017-10-09
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
<?php const APP_ID = "2017093000008****"; const SEC_KEY = "fwaMe87kzqxPLEQn****"; const API_KEY = "fXO11spsZqIG2cYG8G1i****"; const SECRET_KEY = "506c8f9356510d440c17e945552c****"; require_once 'lib/aip-speech-php-sdk-1.6.0/AipSpeech.php'; // 语音 require_once 'lib/baidu_transapi.php'; // 翻译 $aipSpeech = new AipSpeech(APP_ID, API_KEY, SECRET_KEY); /* 识别本地文件 */ $result = $aipSpeech->asr(file_get_contents('static/16k.pcm'), 'pcm', 16000, array()); /* 语音识别出来的字符串 */ $voice_str = $result['result'][0]; /* 翻译 */ $query = $voice_str; $from = isset($_GET['from'])?@$_GET['from']:'zh'; $to = isset($_GET['to'])?@$_GET['to']:'en'; $t_result = translate($query, $from, $to); /* 语音识别出来的字符串 《 翻译 》 成英文 */ $translate_str = $t_result['trans_result'][0]['dst']; /* 将文本合成语音 */ $result = $aipSpeech->synthesis($translate_str, 'zh', 1, array( 'vol' => 5, )); /* 识别正确返回语音二进制 错误则返回json */ if(!is_array($result)){ // file_put_contents('audio.mp3', $result); echo $result; }else { exit(json_encode($result)); }