html5语音转文字实时语音转文字
创始人
2024-09-25 04:48:32

w html5 demo:
链接:https://pan.baidu.com/s/1uJ2EO9FNzFsRE69D_t6mI 提取码:19r5

文档

实时转需要开启录音权限,看文档,或者demo

借助第三方语音转文字技术


上传wav格式语音文件转文字

服务端实现ASR自动语音转文字,提供给前端asr服务器地址,然后前端把需要的语音文件以指定格式发送给服务端,服务端返回转换后的结果

    点击上传  
import WebSockerUtil from "xx/xxx/xxx/";//引入ws工具类  let ws = null;  function webSocketInit(){ 	//服务端提供的ASR服务地址,进行ws连接, 	ws = new WebSockerUtil('ws:xxx/xxx/xx:1008',messageHandler) } webSocketInit();  /** 接收结果 */ function messageHandler(eventData){ 	console.log(eventData,'ws转换结果') 	let resultTxt = '';//结果文字     let rectxt = "" + JSON.parse(jsonMsg.data)['text'];     let asrmodel = JSON.parse(jsonMsg.data)['mode'];     let is_final = JSON.parse(jsonMsg.data)['is_final'];     let timestamp = JSON.parse(jsonMsg.data)['timestamp'];     if (asrmodel == "2pass-offline" || asrmodel == "offline") {         offline_text = offline_text + handleWithTimestamp(rectxt, timestamp); //rectxt; //.replace(/ +/g,"");         resultTxt  = offline_text;     } else {         resultTxt  = rec_text + rectxt; //.replace(/ +/g,"");     } }  /**  自定义上传文件 */ function  customUploadHandler({file}){       let fileAudio = new FileReader();       fileAudio.readAsArrayBuffer(file);       fileAudio.onload = ()=>{         let file_data_array = audioblob.result; //        const audioblob= new Blob([new Uint8Array(file_data_array)], { type: "audio/wav" }); //       const audioSrc = (window.URL || webkitURL).createObjectURL(audioblob);   	     let sampleBuf = new Uint8Array(file_data_array);  	     let CHUNK_SIZE = 960; // for asr chunk_size [5, 10, 5]  	     while (sampleBuf.length >= chunk_size) {              let sendBuf = sampleBuf.slice(0, CHUNK_SIZE);               sampleBuf = sampleBuf.slice(CHUNK_SIZE, sampleBuf.length);               ws.send(sendBuf);           }                      //stop           let chunk_size = new Array(5, 10, 5);           	 var request = {        			 "chunk_size": chunk_size,         		 "wav_name": "h5",         		 "is_speaking": false,         		 "chunk_interval": 10,         		 "mode": 'offline',     		};     		if (sampleBuf.length > 0) {         		ws.send(sampleBuf);     		    sampleBuf = new Int16Array();    			 }    			 ws.send(JSON.stringify(request));       } }  

相关内容

热门资讯

未来三年销售目标突破千亿元!京... 上证报中国证券网讯(记者 刘暄)京东与荣耀4月2日签署战略合作协议,明确未来三年荣耀在京东全渠道销售...
我国科研人员发现99个新物种 我国科研人员发现99个昆虫新物种 为青藏高原生物多样性再添新证 4月1日,我国科研人员在国际动物分类...
兴源自动化取得电芯高效测漏设备... 国家知识产权局信息显示,惠州市兴源自动化设备有限公司取得一项名为“一种电芯高效测漏设备”的专利,授权...
量旋科技完成6亿元C+轮融资 ... 本报讯 (记者张敏)4月3日,深圳量旋科技有限公司(以下简称“量旋科技”)宣布完成6亿元C+轮融资。...
李云泽:推动构建与未来产业全生... 上证报中国证券网讯 据金融监管总局4月3日消息,4月1日,金融监管总局举办党委理论学习中心组集体(扩...