From 8f4254b098b403ae3059a6e700bec356cf3eb099 Mon Sep 17 00:00:00 2001
From: yaooo <272523191@qq.com>
Date: Thu, 12 Oct 2023 16:48:01 +0800
Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0iat=E9=9D=99=E6=80=81?=
=?UTF-8?q?=E8=B5=84=E6=BA=90?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
public/xf_voice/css/base.css | 6 +-
public/xf_voice/index.html | 191 +++++++++++--------------
public/xf_voice/js/transcode.worker.js | 5 +-
public/xf_voice/js/voice.js | 27 ++--
4 files changed, 97 insertions(+), 132 deletions(-)
diff --git a/public/xf_voice/css/base.css b/public/xf_voice/css/base.css
index 65c51ea5c..c7f989ca6 100644
--- a/public/xf_voice/css/base.css
+++ b/public/xf_voice/css/base.css
@@ -1,9 +1,7 @@
.h1 {
text-align: center;
}
-body{
- background-color: transparent !important;
-}
+
.voice-box {
box-sizing : border-box;
display : flex;
@@ -11,7 +9,7 @@ body{
margin : 50px auto;
padding : 50px;
width : 60%;
-
+ border : 1px solid gray;
border-radius : 3px;
}
diff --git a/public/xf_voice/index.html b/public/xf_voice/index.html
index 7156f3bb5..c48f9233b 100644
--- a/public/xf_voice/index.html
+++ b/public/xf_voice/index.html
@@ -1,107 +1,86 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Hello! 请说出你想说话。。。!
-
-

-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+ 迅飞语音听写(流式版)WebAPI
+
+
+
+
+
+ 迅飞语音听写(流式版)WebAPI
+
+
+
+
+
+
+
Hello! 请说出你想说话。。。!
+
+

+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/public/xf_voice/js/transcode.worker.js b/public/xf_voice/js/transcode.worker.js
index 9d5928f8f..e79c1e1af 100644
--- a/public/xf_voice/js/transcode.worker.js
+++ b/public/xf_voice/js/transcode.worker.js
@@ -5,8 +5,7 @@
}
let transAudioData = {
- transcode(audioData) {
-
+ transcode(audioData) {
let output = transAudioData.to16kHz(audioData)
output = transAudioData.to16BitPCM(output)
output = Array.from(new Uint8Array(output.buffer))
@@ -42,7 +41,5 @@
}
return dataView
}
-
-
}
})();
\ No newline at end of file
diff --git a/public/xf_voice/js/voice.js b/public/xf_voice/js/voice.js
index b4d963268..7732e9075 100644
--- a/public/xf_voice/js/voice.js
+++ b/public/xf_voice/js/voice.js
@@ -73,8 +73,7 @@
alert('请正确配置【迅飞语音听写(流式版)WebAPI】服务接口认证信息!');
} else {
self.webWorker = new Worker('./js/transcode.worker.js');
- self.webWorker.onmessage = function (event) {
-
+ self.webWorker.onmessage = function (event) {
self.audioData.push(...event.data);
};
}
@@ -124,8 +123,7 @@
this.webSocket = iatWS;
this.setStatus('init');
iatWS.onopen = e => {
- this.setStatus('ing');
- console.log('连接成功')
+ this.setStatus('ing');
// 重新开始录音
setTimeout(() => {
this.webSocketSend();
@@ -218,8 +216,7 @@
};
// 向webSocket发送数据(音频二进制数据经过Base64处理)
webSocketSend() {
- if (this.webSocket.readyState !== 1) return false;
-
+ if (this.webSocket.readyState !== 1) return false;
// 音频数据
const audioData = this.audioData.splice(0, 1280);
const params = {
@@ -265,8 +262,7 @@
clearInterval(this.handlerInterval);
}
return false;
- };
-
+ };
// 中间帧
this.webSocket.send(
JSON.stringify({
@@ -281,10 +277,8 @@
}, 40);
};
// 识别结束 webSocket返回数据
- webSocketRes(resultData) {
-
- let jsonData = JSON.parse(resultData);
- console.log(JSON.stringify( jsonData))
+ webSocketRes(resultData) {
+ let jsonData = JSON.parse(resultData);
if (jsonData.data && jsonData.data.result) {
let data = jsonData.data.result;
let str = '';
@@ -312,17 +306,14 @@
}
}
if (jsonData.code === 0 && jsonData.data.status === 2) {
- this.webSocket.close();
-
+ this.webSocket.close();
}
if (jsonData.code !== 0) {
- this.webSocket.close();
-
+ this.webSocket.close();
}
};
// 启动录音
- recorderStart() {
-
+ recorderStart() {
if (!this.audioContext) {
this.recorderInit();
} else {