点这里 语音搜索
历史搜索
- 动画片
- 电视剧
- 纪录片
- 特别节目
')
//$("#toast").stop(true,true).fadeIn(0);
setTimeout(function(){
//$("#toast").fadeOut(100,function(){
$("#toast").remove();
//})
},2000);
if(stop){
$(".voiceShadow").hide();
$(".voiceShadow .shadow_con .voiceCon .state01").removeClass("cur").show();
$(".voiceShadow .shadow_con .voiceCon .state01.cur .syText").text("正在听您讲话");
$(".voiceShadow .shadow_con .voiceCon .state02").hide();
$(".voiceBottom").removeClass("cur");
}
}
var rec,closeTrue = true;
/**调用open打开录音请求好录音权限**/
function recOpen(id){//一般在显示出录音按钮或相关的录音界面时进行此方法调用,后面用户点击开始录音时就能畅通无阻了
console.log("recOpen浏览器录音");
rec=null;
rec = Recorder({
type:"unknown",sampleRate:16000,bitRate:16 //mp3格式,指定采样率hz、比特率kbps,其他参数使用默认配置;注意:是数字的参数必须提供数字,不要用字符串;需要使用的type类型,需提前把格式支持文件加载进来,比如使用wav格式需要提前加载wav.js编码引擎
,onProcess:function(buffers,powerLevel,bufferDuration,bufferSampleRate,newBufferIdx,asyncEnd){
RealTimeSendTry(rec,false);
}
});
rec.open(function(){//打开麦克风授权获得相关资源
$(".voiceShadow").show();
recStartWav()
},function(msg,isUserNotAllow){//用户拒绝未授权或不支持
toast('您未授权麦克风权限',true);
console.log((isUserNotAllow?"UserNotAllow,":"")+"打开录音失败:"+msg,1);
});
window.waitDialogClick=function(){
console.log("打开录音失败:权限请求被忽略,用户主动点击的弹窗",1);
};
};
var handerSetInterval;
function talkWX(){ //微信录音
$(".voiceBtn").on("touchstart",function(e){
searchText = "";
wx.stopRecord();
closeTrue = true;
wx.startRecord({
success: function(){
handerSetInterval = setInterval(function() {
wxStopRecord();
toast("已超时,为您自动跳转",false);
clearInterval(handerSetInterval);
}, 18000);
},
fail: function (){
console.log("拒接,了 01")
toast('用户拒绝授权录音',true);
},
complete: function (data){
if(data.errMsg == "startRecord:cancel"){
toast('您未授权麦克风权限',true);
$(".voiceShadow").hide();
$(".voiceShadow .shadow_con .voiceCon .state01").removeClass("cur").show();
$(".voiceShadow .shadow_con .voiceCon .state01.cur .syText").text("正在听您讲话");
$(".voiceShadow .shadow_con .voiceCon .state02").hide();
wx.stopRecord()
}else if(data.errMsg == "startRecord:ok"){
$(".voiceShadow").show();
}
}
});
})
$(".voiceBottom").on("touchstart",function(e){
if(!$(".voiceBottom").hasClass("cur")){
wxStopRecord()
}
})
}
function wxStopRecord(){
$(".voiceShadow .shadow_con .voiceCon .state01").hide();
$(".voiceShadow .shadow_con .voiceCon .state02").show();
$(".voiceBottom").addClass("cur");
wx.stopRecord({
success: function (res) {
clearInterval(handerSetInterval);
var localId = res.localId;
if (localId == '' || localId == "undefined") {
toast('呜呜,走神了,再问我一次吧',true);
return;
}else{
wx.uploadVoice({
localId: localId, //需要上传的音频的本地ID,由stopRecord接口获得
isShowProgressTips:0, //默认为1,显示进度提示
success: function (res){
ajax01(wxAsr,{
"type":"asr",
"cookieId":getCookieCna,
"data":{"audioId":res.serverId}
},function(data){
if(res.serverId == data.result.audioId){
searchText = data.result.asrResult;
if(searchText == "" || searchText == null || searchText == "undefined"){
toast('呜呜,走神了,再问我一次吧',true);
return false;
}else{
if(closeTrue){
$(".voiceShadow").hide();
$(".voiceShadow .shadow_con .voiceCon .state01").removeClass("cur").show();
$(".voiceShadow .shadow_con .voiceCon .state01.cur .syText").text("正在听您讲话");
$(".voiceShadow .shadow_con .voiceCon .state02").hide();
$(".voiceBottom").removeClass("cur");
$("#toast").remove();
//window.history.pushState(null, null,originUrl);
if(searchText == ""){
searchText = defaultSearchText;
}
clickSuggest(searchText,2);
}
}
}
})
},
fail: function (res){
toast('呜呜,走神了,再问我一次吧',true);
}
});
}
},
fail: function (res){
toast('呜呜,走神了,再问我一次吧',true);
}
});
}
function talkWB(){ //浏览器录音
$(".voiceBtn").on("touchstart",function(e){
$(".voiceShadow .shadow_con .voiceCon .state01 .syText").text("正在听您讲话");
closeTrue = true;
recOpen(1)
})
$(".voiceBottom").on("touchstart",function(e){
clearInterval(handerSetInterval);
if(!$(".voiceBottom").hasClass("cur")){
$(".voiceShadow .shadow_con .voiceCon .state01").hide();
$(".voiceShadow .shadow_con .voiceCon .state02").show();
$(".voiceBottom").addClass("cur");
recStop();
}
})
}
var socket;
var WebSocketLoop = true;
var WebSocketLoopLength = 0;
var WebSocketClose = true;
function WebSocketOpen(){
socket = new WebSocket("wss://asr.tv.cctv.com:8085/ws/v1/asr");
socket.addEventListener('open', function (event) {
searchText = "";
});
socket.addEventListener('close', function (event){
WebSocketClose = true;
if(WebSocketLoop && WebSocketLoopLength < 3){
WebSocketOpen();
}else if(WebSocketLoop){
WebSocketLoopLength = 0;
//连续调用3次如果失败走提示
toast('失联了,请稍后重试',true); //asr接口数据返回异常
}
});
socket.addEventListener('error', function (event) {
WebSocketLoop = true;
WebSocketLoopLength ++;
});
socket.addEventListener('message', function (event) {
WebSocketClose = false;
WebSocketLoop = false;
WebSocketLoopLength = 0;
var msg = JSON.parse(event.data);
if(msg.type == "asr"){
if(msg.result.completed == false){
$(".voiceShadow .shadow_con .voiceCon .state01").addClass("cur");
$(".voiceShadow .shadow_con .voiceCon .state01 .syText").html("");
var pcTextCur = searchText + msg.result.asrResult
if(pcTextCur.length > 40){
pcTextCur = "...."+pcTextCur.substring(pcTextCur.length-39);
}
$(".voiceShadow .shadow_con .voiceCon .state01 .syText").html(pcTextCur);
}else if(msg.result.completed == true){
searchText = searchText + msg.result.asrResult;
}
}else if(msg.type == "final" && closeTrue){
$(".voiceShadow").hide();
$(".voiceShadow .shadow_con .voiceCon .state01").removeClass("cur").show();
$(".voiceShadow .shadow_con .voiceCon .state01.cur .syText").text("正在听您讲话");
$(".voiceShadow .shadow_con .voiceCon .state02").hide();
$(".voiceBottom").removeClass("cur");
recStop();
$("#toast").remove();
clearInterval(handerSetInterval);
//window.history.pushState(null, null,originUrl);
if(searchText == ""){
searchText = defaultSearchText;
}
clickSuggest(searchText,2);
}
});
}
var testOutputWavLog=false;
var testSampleRate=16000;
var testBitRate=16;
var SendInterval=1;
//重置环境
var RealTimeSendTryReset=function(type){
realTimeSendTryType=type;
realTimeSendTryTime=0;
};
var realTimeSendTryType;
var realTimeSendTryEncBusy;
var realTimeSendTryTime=0;
var realTimeSendTryNumber;
var transferUploadNumberMax;
var realTimeSendTryChunk;
//=====实时处理核心函数==========
var RealTimeSendTry=function(rec,isClose){
var t1=Date.now(),endT=0,recImpl=Recorder.prototype;
if(realTimeSendTryTime==0){
realTimeSendTryTime=t1;
realTimeSendTryEncBusy=0;
realTimeSendTryNumber=0;
transferUploadNumberMax=0;
realTimeSendTryChunk=null;
};
if(!isClose && t1-realTimeSendTryTime= 0) ? type = "GET":type = "POST";
(data == "") ? data="":data=JSON.stringify(data);
$.ajax({
url:url,
type:type,
data:data,
contentType:"application/json",
cache:true,
dataType:'json',
crossDomain: true,
success: function(data){cb(data)},
timeout:5000,
error:function(jqXHR, textStatus, errorThrown){
//ajaxError(jqXHR.responseText);
toast("需要休息一下,麻烦稍后再试",true);
clearInterval(handerSetInterval);
closeTrue = false;
$(".voiceShadow").hide();
$(".voiceShadow .shadow_con .voiceCon .state01").removeClass("cur").show();
$(".voiceShadow .shadow_con .voiceCon .state01.cur .syText").text("正在听您讲话");
$(".voiceShadow .shadow_con .voiceCon .state02").hide();
$(".voiceBottom").removeClass("cur");
if(appDoubt == "WB"){
socket.close();
recStop();
}else if(appDoubt == "WX"){
wx.stopRecord()
}
}
});
}
function getCookieJiankang(name) {
var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
if (arr = document.cookie.match(reg)) return unescape(arr[2]);
else return null
}
function shareWX(){
var data={"appid":"aibang","serviceId":"tvcctv","url":encodeURIComponent(encodeURIComponent(window.location.href))}; //微信授权
getAjax("//api.cntv.cn/list/getWeiXinSignature",data,weixinSucess);
}
//微信授权
function getAjax(url,data,cb){
$.ajax({
url:url,
type:"get",
data:data,
dataType:'jsonp',
jsonp:"cb",
jsonpCallback:"cb2",
cache:true,
success: function(_data){cb(_data);},
timeout:10000,
error:function(jqXHR, textStatus, errorThrown){
toast("请求超时,请检查网络或者重新刷新页面!",true)
}
});
}
/*微信授权区域*/
function weixinSucess(data){
wx.config({
debug: false,
appId: "wxd92107b6811c5422",
timestamp: data.data.timestamp,
nonceStr: data.data.nonceStr,
signature: data.data.signature,
jsApiList: ['updateTimelineShareData','updateAppMessageShareData','onMenuShareQZone','onVoiceRecordEnd','startRecord','stopRecord','translateVoice','playVoice','uploadVoice',] // 功能列表,我们要使用JS-SDK的什么功能
});
}
wx.ready(function(){
wx.stopRecord();
if(voiceOpen == "open"){
$(".voiceShadow").show();
wx.startRecord({
success: function(){
handerSetInterval = setInterval(function() {
toast("已超时,为您自动跳转",false);
clearInterval(handerSetInterval);
wxStopRecord();
}, 18000);
},
fail: function (){
wx.stopRecord();
console.log("默认拒接,了 01")
toast("用户拒绝授权录音",true)
},
complete: function (data){
if(data.errMsg == "startRecord:cancel"){
toast('您未授权麦克风权限',true);
$(".voiceShadow").hide();
$(".voiceShadow .shadow_con .voiceCon .state01").removeClass("cur").show();
$(".voiceShadow .shadow_con .voiceCon .state01.cur .syText").text("正在听您讲话");
$(".voiceShadow .shadow_con .voiceCon .state02").hide();
wx.stopRecord()
}else if(data.errMsg == "startRecord:ok"){
$(".voiceShadow").show();
}
}
})
}
// 获取“分享到朋友圈”按钮点击状态及自定义分享内容接口
wx.updateTimelineShareData({
title: '央视节目官网搜索', // 分享标题
link:window.location.href,
imgUrl: "https:"+"//p2.img.cctvpic.com/photoAlbum/page/performance/img/2021/5/11/1620700276801_447.jpg" // 分享图标
});
// 获取“分享给朋友”按钮点击状态及自定义分享内容接口
wx.updateAppMessageShareData({
title: '央视节目官网搜索', // 分享标题
desc: "", // 分享描述
link:window.location.href,
imgUrl: "https:"+"//p2.img.cctvpic.com/photoAlbum/page/performance/img/2021/5/11/1620700276801_447.jpg" // 分享图标
});
talkWX();
onBridgeReady_OptionMenu();
});
wx.error(function(res){
toast("微信授权失败,重新刷新页面",true);
});
function onBridgeReady_OptionMenu(){
WeixinJSBridge.call('showOptionMenu');
}
function getvl(name){
var reg = new RegExp("(^|\\?|&)"+ name +"=([^&]*)(\\s|&|$)", "i");
if (reg.test(decodeURIComponent(location.href))) return unescape(RegExp.$2.replace(/\+/g, " "));
return "";
}
$(".voiceShadow .shadow_con .close").click(function(){
clearInterval(handerSetInterval);
closeTrue = false;
$(".voiceShadow").hide();
$(".voiceShadow .shadow_con .voiceCon .state01").removeClass("cur").show();
$(".voiceShadow .shadow_con .voiceCon .state01.cur .syText").text("正在听您讲话");
$(".voiceShadow .shadow_con .voiceCon .state02").hide();
$(".voiceBottom").removeClass("cur");
if(appDoubt == "WB"){
socket.close();
recStop();
}else if(appDoubt == "WX"){
wx.stopRecord()
}
})
function isdingding_20190304(){
//判断是不是钉钉
var ua = navigator.userAgent.toLowerCase();
return ua.indexOf("dingtalk") >= 0;
}
if(isdingding_20190304()){
dd.ready(function(){
dd.biz.navigation.setRight({
show: true,//控制按钮显示, true 显示, false 隐藏, 默认true
control: true,//是否控制点击事件,true 控制,false 不控制, 默认false
text: '',//控制显示文本,空字符串表示显示默认文本
onSuccess : function(result) {
//如果control为true,则onSuccess将在发生按钮点击事件被回调
dd.biz.util.share({
type: 0, //分享类型,0:全部组件 默认; 1:只能分享到钉钉;2:不能分享,只有刷新按钮
url: window.location.href,
content: '',
title: '央视节目官网搜索',
image: "https:"+"//p2.img.cctvpic.com/photoAlbum/page/performance/img/2021/5/11/1620700276801_447.jpg", // 分享图标
onSuccess: function() {},
onFail: function(err) {}
})
},
onFail : function(err) {}
});
})
}