国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > PHP > 正文

百度大腦和圖靈機器人制作一個簡單的自動聊天機器人【PHP代碼】

2019-11-10 20:07:46
字體:
來源:轉載
供稿:網友

可以和機器人聊天 文字發送消息 網頁進行語音回復

這里主要用到了兩個接口

一個是百度大腦  用來實現語音合成

一個是圖靈機器人用來實現自動聊天

以下是代碼分兩個版本 版本一是沒有語音合成 版本二是加上語音合成功能

php版本最低5.5

版本一:

<?php$api='http://www.tuling123.com/openapi/api';$cont=isset($_POST['con'])?$_POST['con']:'';$p=isset($_POST['p'])?$_POST['p']:'';if($p!=1){    echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><div style="width:600px; padding:10px; height:800px; border:1px solid #ccc; margin:15px auto;">    <!-- <form action="jqr.php" method="post"> -->    <div id="odiv" style="height:760px;">';}function send_post($url, $post_data) {  $postdata = http_build_query($post_data);  $options = array(    'http' => array(      'method' => 'POST',      'header' => 'Content-type:application/x-www-form-urlencoded',      'content' => $postdata,      'timeout' => 15 * 60 // 超時時間(單位:s)    )  );  $context = stream_context_create($options);  $result = file_get_contents($url, false, $context);  return $result;}if($p){ $post_data = array(  'key' => 'afdf361909844a6395108f8406a15b02',//請自己設置key  'info'=>$cont,  'userid'=>'456789',//用于辨識用戶 測試階段也可以隨意寫);$conts=send_post($api, $post_data);$conts=explode('text":"',$conts)[1];$conts=explode('"',$conts)[0];echo '<li style="float:right;width:auto"><img src="">'.$cont.'</li>'.'<li style="float:left; width:100%;">'.$conts.'</li>';}if(!$p){    echo "</div><div style='width:600px; margin:5px auto; ''><input id='b01' type='text' style='height:30px; width:540px;'' name='con'><button id='but' style='height:30px;''>提交</button></div><!-- </form> --></div>";}if(!$p){echo '<script src="http://apps.bdimg.com/libs/jquery/1.6.4/jquery.js" type="text/javascript"></script></script><script>    $("button").click(function(){    txt=$("#b01").val();    $.post("jqr.php",{con:txt,p:1},function(result){    	var htmla=$("#odiv").html() + result;   		var odiv =  document.getElementById("odiv");   		odiv.innerHTML = htmla+"<br>";  	})})</script>';}?>

版本二:

<?php$api='http://www.tuling123.com/openapi/api';$cont=isset($_POST['con'])?$_POST['con']:'';$p=isset($_POST['p'])?$_POST['p']:'';if($p!=1){    echo '<!DOCTYPE html><html><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"><style type=text/CSS>*{list-style:none}</style></head><div style="width:600px; padding:10px; height:800px; border:1px solid #ccc; margin:15px auto;">    <!-- <form action="jqr.php" method="post"> -->    <div id="odiv" style="height:760px;">';}function send_post($url, $post_data) {  $postdata = http_build_query($post_data);  $options = array(    'http' => array(      'method' => 'POST',      'header' => 'Content-type:application/x-www-form-urlencoded',      'content' => $postdata,      'timeout' => 15 * 60 // 超時時間(單位:s)    )  );  $context = stream_context_create($options);  $result = file_get_contents($url, false, $context);  return $result;}if($p){ $post_data = array(  'key' => 'afdf361909844a6395108f8406a15b02',  'info'=>$cont,  'userid'=>'456789',);$conts=send_post($api, $post_data);$conts=explode('text":"',$conts)[1];$conts=explode('"',$conts)[0];echo '<li style="float:right;width:auto">'.$cont.'</li>'.'<li style="float:left; width:100%;" style="width:40px; height:20px line-height:20px;"><audio controls style="width:40px; height:10px;" ><source src="http://hope.tk2a.com/baidu.php?con='.$conts.'" type="audio/ogg"></audio>'.$conts.'</li>';}if(!$p){    echo "</div><div style='width:600px; margin:5px auto; style='width:40px; height:10px;' ''><input id='b01' type='text' style='height:30px; width:540px;'' name='con'><button id='but' style='height:30px;''>提交</button></div><!-- </form> --></div>";}if(!$p){echo '<script src="jquery-1.6.4.min.js" type="text/Javascript"></script></script><script>    $("button").click(function(){    txt=$("#b01").val();    $.post("ltt.php",{con:txt,p:1},function(result){    	var htmla=$("#odiv").html() + result;   		var odiv =  document.getElementById("odiv");   		odiv.innerHTML = htmla+"<br>";  	})})</script>';}?>


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 丰城市| 五河县| 江城| 印江| 遵化市| 来宾市| 娄烦县| 将乐县| 化州市| 商洛市| 临夏市| 新竹市| 城固县| 城口县| 三门峡市| 措勤县| 盐源县| 修文县| 闻喜县| 若羌县| 黄石市| 彭阳县| 怀宁县| 府谷县| 和顺县| 大田县| 日照市| 特克斯县| 龙陵县| 沙湾县| 太原市| 巴塘县| 宁远县| 柳江县| 兰州市| 石城县| 五寨县| 富顺县| 洛扎县| 莒南县| 罗江县|