失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > java可以编写siri_打造Android的中文Siri语音助手(一)

java可以编写siri_打造Android的中文Siri语音助手(一)

时间:2022-12-16 13:48:28

相关推荐

java可以编写siri_打造Android的中文Siri语音助手(一)

publicclassXiaoI{

privateStringWebbot_Path="/engine/widget1007/webbot.js?encoding=utf-8";

privateStringSend_Path="http://122.226.240.164/engine/widget1007/send.js?encoding=utf-8&";

privateStringRecv_Path="http://122.226.240.164/engine/widget1007/recv.js?encoding=utf-8&";

privateStringmSessionId=null;

privateHttpClienthttpClient=null;

publicbooleaninitialize(){

booleansuccess=false;

HttpParamshttpParams=newBasicHttpParams();

HttpConnectionParams.setConnectionTimeout(httpParams,30000);

HttpConnectionParams.setSoTimeout(httpParams,30000);

httpClient=newDefaultHttpClient(httpParams);

try{

StringstrGetId=Webbot_Path;

HttpGethttpRequest=newHttpGet(strGetId);

HttpResponsehttpResponse=httpClient.execute(httpRequest);

if(httpResponse.getStatusLine().getStatusCode()==HttpURLConnection.HTTP_OK){

StringstrResult=EntityUtils.toString(httpResponse

.getEntity());

Patternp=pile("sessionId=.(\\d+)");//getsessionId

Matcherm=p.matcher(strResult);

if(m.find()){

mSessionId=m.group(1);

StringstrSendJoin=Send_Path+"SID="+mSessionId

+"&USR="+mSessionId+"&CMD=JOIN&r=";

HttpGethttpRequest1=newHttpGet(strSendJoin);

httpResponse=httpClient.execute(httpRequest1);

StringstrRevAsk=Recv_Path+"SID="+mSessionId

+"&USR="+mSessionId+"&r=";

HttpGethttpRequest2=newHttpGet(strRevAsk);

httpResponse=httpClient.execute(httpRequest2);

success=true;

}

}

}catch(ClientProtocolExceptione){

e.printStackTrace();

}catch(IOExceptione){

e.printStackTrace();

}catch(Exceptione){

e.printStackTrace();

}finally{

returnsuccess;

}

}

publicvoidsendMsg(Stringmsg){

StringstrTalksend=Send_Path+"SID="+mSessionId+"&USR="

+mSessionId+"&CMD=CHAT&SIG=You&MSG="+msg

+"&FTN=&FTS=&FTC=&r=";

HttpGethttpRequest=newHttpGet(strTalksend);

try{

httpClient.execute(httpRequest);

}catch(ClientProtocolExceptione){

//TODOAuto-generatedcatchblock

e.printStackTrace();

}catch(IOExceptione){

//TODOAuto-generatedcatchblock

e.printStackTrace();

}

}

publicStringrevMsg(){

StringstrTalkRec=Recv_Path+"SID="+mSessionId+"&USR="

+mSessionId+"&r=";

HttpGethttpRequest=newHttpGet(strTalkRec);

Stringmsg=null;

try{

HttpResponsehttpResponse=httpClient.execute(httpRequest);

if(httpResponse.getStatusLine().getStatusCode()==200){

StringmsgTmp=EntityUtils.toString(httpResponse.getEntity());

Patternp=pile("\"MSG\":\"(.*?)\"");

Matcherm=p.matcher(msgTmp);

if(m.find()){

msg=m.group(1);

}

}

}catch(ClientProtocolExceptione){

//TODOAuto-generatedcatchblock

e.printStackTrace();

}catch(IOExceptione){

//TODOAuto-generatedcatchblock

e.printStackTrace();

}

returnmsg;

}

}

如果觉得《java可以编写siri_打造Android的中文Siri语音助手(一)》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。