前端语言识别提交

This commit is contained in:
yanyuxiyangzk@126.com 2024-04-14 17:37:04 +08:00
parent 8f715d2477
commit 0cf9f4902d
2 changed files with 91 additions and 31 deletions

View File

@ -52,6 +52,7 @@
<label><input name="asr_mode" type="radio" value="2pass" />2pass </label>&nbsp;&nbsp; <label><input name="asr_mode" type="radio" value="2pass" />2pass </label>&nbsp;&nbsp;
<label><input name="asr_mode" type="radio" value="online" checked="true"/>online </label>&nbsp;&nbsp; <label><input name="asr_mode" type="radio" value="online" checked="true"/>online </label>&nbsp;&nbsp;
<label><input name="asr_mode" type="radio" value="2pass-offline" />2pass-offline </label>&nbsp;&nbsp;
<label><input name="asr_mode" type="radio" value="offline" />offline </label> <label><input name="asr_mode" type="radio" value="offline" />offline </label>
</div> </div>
@ -92,37 +93,37 @@
</body> </body>
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
$(document).ready(function() { // $(document).ready(function() {
var host = window.location.hostname // var host = window.location.hostname
var ws = new WebSocket("ws://"+host+":8000/humanecho"); // var ws = new WebSocket("ws://"+host+":8000/humanecho");
//document.getElementsByTagName("video")[0].setAttribute("src", aa["video"]); // //document.getElementsByTagName("video")[0].setAttribute("src", aa["video"]);
ws.onopen = function() { // ws.onopen = function() {
console.log('Connected'); // console.log('Connected');
}; // };
ws.onmessage = function(e) { // ws.onmessage = function(e) {
console.log('Received: ' + e.data); // console.log('Received: ' + e.data);
data = e // data = e
var vid = JSON.parse(data.data); // var vid = JSON.parse(data.data);
console.log(typeof(vid),vid) // console.log(typeof(vid),vid)
//document.getElementsByTagName("video")[0].setAttribute("src", vid["video"]); // //document.getElementsByTagName("video")[0].setAttribute("src", vid["video"]);
}; // };
ws.onclose = function(e) { // ws.onclose = function(e) {
console.log('Closed'); // console.log('Closed');
}; // };
flvPlayer = mpegts.createPlayer({type: 'flv', url: "http://"+host+":8080/live/livestream.flv", isLive: true, enableStashBuffer: false}); // flvPlayer = mpegts.createPlayer({type: 'flv', url: "http://"+host+":8080/live/livestream.flv", isLive: true, enableStashBuffer: false});
flvPlayer.attachMediaElement(document.getElementById('video_player')); // flvPlayer.attachMediaElement(document.getElementById('video_player'));
flvPlayer.load(); // flvPlayer.load();
flvPlayer.play(); // flvPlayer.play();
$('#echo-form').on('submit', function(e) { // $('#echo-form').on('submit', function(e) {
e.preventDefault(); // e.preventDefault();
var message = $('#message').val(); // var message = $('#message').val();
console.log('Sending: ' + message); // console.log('Sending: ' + message);
ws.send(message); // ws.send(message);
$('#message').val(''); // $('#message').val('');
}); // });
}); // });
</script> </script>
</html> </html>

View File

@ -50,6 +50,7 @@ var file_data_array; // array to save file data
var totalsend=0; var totalsend=0;
const startTime = Date.now();
var now_ipaddress=window.location.href; var now_ipaddress=window.location.href;
now_ipaddress=now_ipaddress.replace("https://","wss://"); now_ipaddress=now_ipaddress.replace("https://","wss://");
@ -343,8 +344,30 @@ function handleWithTimestamp(tmptext,tmptime)
} }
// 语音识别结果; 对jsonMsg数据解析,将识别结果附加到编辑框中 // 语音识别结果; 对jsonMsg数据解析,将识别结果附加到编辑框中
function getJsonMessage( jsonMsg ) { function getJsonMessage( jsonMsg ) {
const currentTime = Date.now();
res_time = startTime-currentTime;
//时间之差在4秒则发送消息
let waitTime = 5000;
if(res_time>=waitTime){
//自动发送消息
('#echo-form').on('submit', function(e) {
e.preventDefault();
var message = $('#message').val();
console.log('Sending: ' + message);
ws.send(message);
$('#message').val('');
});
startTime = currentTime;
return;
}
//console.log(jsonMsg); //console.log(jsonMsg);
console.log( "message: " + JSON.parse(jsonMsg.data)['text'] ); console.log( "message: " + JSON.parse(jsonMsg.data)['text'] );
var rectxt=""+JSON.parse(jsonMsg.data)['text']; var rectxt=""+JSON.parse(jsonMsg.data)['text'];
@ -368,6 +391,8 @@ function getJsonMessage( jsonMsg ) {
varArea_message.value=rec_text; varArea_message.value=rec_text;
console.log( "offline_text: " + asrmodel+","+offline_text); console.log( "offline_text: " + asrmodel+","+offline_text);
console.log( "rec_text: " + rec_text); console.log( "rec_text: " + rec_text);
console.log( "isfilemode: " + isfilemode);
console.log( "is_final: " + is_final);
if (isfilemode==true && is_final==false){ if (isfilemode==true && is_final==false){
console.log("call stop ws!"); console.log("call stop ws!");
play_file(); play_file();
@ -565,4 +590,38 @@ function recProcess( buffer, powerLevel, bufferDuration, bufferSampleRate,newBuf
} }
} }
$(document).ready(function() {
var host = window.location.hostname
var ws = new WebSocket("ws://"+host+":8000/humanecho");
//document.getElementsByTagName("video")[0].setAttribute("src", aa["video"]);
ws.onopen = function() {
console.log('Connected');
};
ws.onmessage = function(e) {
console.log('Received: ' + e.data);
data = e
var vid = JSON.parse(data.data);
console.log(typeof(vid),vid)
//document.getElementsByTagName("video")[0].setAttribute("src", vid["video"]);
};
ws.onclose = function(e) {
console.log('Closed');
};
flvPlayer = mpegts.createPlayer({type: 'flv', url: "http://"+host+":8080/live/livestream.flv", isLive: true, enableStashBuffer: false});
flvPlayer.attachMediaElement(document.getElementById('video_player'));
flvPlayer.load();
flvPlayer.play();
$('#echo-form').on('submit', function(e) {
e.preventDefault();
var message = $('#message').val();
console.log('Sending: ' + message);
ws.send(message);
$('#message').val('');
});
});