From 0cf7339171ee136721059c3c185b5d92d160b17a Mon Sep 17 00:00:00 2001
From: zhaomingwork <61895407+zhaomingwork@users.noreply.github.com>
Date: 星期一, 21 八月 2023 14:43:07 +0800
Subject: [PATCH] add hotwords for h5 and java (#876)
---
funasr/runtime/html5/static/main.js | 44 ++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 42 insertions(+), 2 deletions(-)
diff --git a/funasr/runtime/html5/static/main.js b/funasr/runtime/html5/static/main.js
index 7e3573d..7e5a49a 100644
--- a/funasr/runtime/html5/static/main.js
+++ b/funasr/runtime/html5/static/main.js
@@ -172,6 +172,17 @@
}
}
+function getHotwords(){
+ var obj = document.getElementById("varHot");
+
+ if(typeof(obj) == 'undefined' || obj==null || obj.value.length<=0){
+ return "";
+ }
+ let val = obj.value.toString();
+ console.log("hotwords="+val);
+ return val;
+
+}
function getAsrMode(){
var item = null;
@@ -193,7 +204,34 @@
return item;
}
+function handleWithTimestamp(tmptext,tmptime)
+{
+ console.log( "tmptext: " + tmptext);
+ console.log( "tmptime: " + tmptime);
+ if(tmptime==null || tmptime=="undefined" || tmptext.length<=0)
+ {
+ return tmptext;
+ }
+ tmptext=tmptext.replace(/銆�/g, ","); // in case there are a lot of "銆�"
+ var words=tmptext.split(",");
+ var jsontime=JSON.parse(tmptime.replace(/\]\]\[\[/g, "],[")); // in case there are a lot segments by VAD
+ var char_index=0;
+ var text_withtime="";
+ for(var i=0;i<words.length;i++)
+ {
+ if(words[i]=="undefined" || words[i].length<=0)
+ {
+ continue;
+ }
+ console.log("words===",words[i]);
+ console.log( "words: " + words[i]+",time="+jsontime[char_index][0]/1000);
+ text_withtime=text_withtime+jsontime[char_index][0]/1000+":"+words[i]+"\n";
+ char_index=char_index+words[i].length;
+ }
+ return text_withtime;
+
+}
// 璇煶璇嗗埆缁撴灉; 瀵筳sonMsg鏁版嵁瑙f瀽,灏嗚瘑鍒粨鏋滈檮鍔犲埌缂栬緫妗嗕腑
function getJsonMessage( jsonMsg ) {
//console.log(jsonMsg);
@@ -201,9 +239,11 @@
var rectxt=""+JSON.parse(jsonMsg.data)['text'];
var asrmodel=JSON.parse(jsonMsg.data)['mode'];
var is_final=JSON.parse(jsonMsg.data)['is_final'];
- if(asrmodel=="2pass-offline")
+ var timestamp=JSON.parse(jsonMsg.data)['timestamp'];
+ if(asrmodel=="2pass-offline" || asrmodel=="offline")
{
- offline_text=offline_text+rectxt; //.replace(/ +/g,"");
+
+ offline_text=offline_text+handleWithTimestamp(rectxt,timestamp); //rectxt; //.replace(/ +/g,"");
rec_text=offline_text;
}
else
--
Gitblit v1.9.1