From ce984a9f8b70c1c2da725f85eee0e2cfb9672275 Mon Sep 17 00:00:00 2001
From: yaooo <272523191@qq.com>
Date: Thu, 12 Oct 2023 15:21:14 +0800
Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E8=AF=AD=E9=9F=B3=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/.htaccess | 0
public/xf_voice/css/base.css | 6 +-
public/xf_voice/index.html | 190 ++++++++++++++++++---------------
public/xf_voice/js/voice.js | 27 +++--
public/xf_voice/nginx.htaccess | 0
5 files changed, 127 insertions(+), 96 deletions(-)
delete mode 100644 public/xf_voice/.htaccess
delete mode 100644 public/xf_voice/nginx.htaccess
diff --git a/public/xf_voice/.htaccess b/public/xf_voice/.htaccess
deleted file mode 100644
index e69de29bb..000000000
diff --git a/public/xf_voice/css/base.css b/public/xf_voice/css/base.css
index c7f989ca6..65c51ea5c 100644
--- a/public/xf_voice/css/base.css
+++ b/public/xf_voice/css/base.css
@@ -1,7 +1,9 @@
.h1 {
text-align: center;
}
-
+body{
+ background-color: transparent !important;
+}
.voice-box {
box-sizing : border-box;
display : flex;
@@ -9,7 +11,7 @@
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 f9a510466..8f19e0f45 100644
--- a/public/xf_voice/index.html
+++ b/public/xf_voice/index.html
@@ -1,86 +1,106 @@
-
-
-
-
-
-
-
- 迅飞语音听写(流式版)WebAPI
-
-
-
-
-
- 迅飞语音听写(流式版)WebAPI
-
-
-
-
-
-
-
Hello! 请说出你想说话。。。!
-
-

-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Hello! 请说出你想说话。。。!
+
+

+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/public/xf_voice/js/voice.js b/public/xf_voice/js/voice.js
index 7732e9075..977c49cef 100644
--- a/public/xf_voice/js/voice.js
+++ b/public/xf_voice/js/voice.js
@@ -73,7 +73,8 @@
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);
};
}
@@ -123,7 +124,8 @@
this.webSocket = iatWS;
this.setStatus('init');
iatWS.onopen = e => {
- this.setStatus('ing');
+ this.setStatus('ing');
+ console.log('连接成功')
// 重新开始录音
setTimeout(() => {
this.webSocketSend();
@@ -216,7 +218,8 @@
};
// 向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 = {
@@ -262,7 +265,8 @@
clearInterval(this.handlerInterval);
}
return false;
- };
+ };
+ console.log(this.audioData)
// 中间帧
this.webSocket.send(
JSON.stringify({
@@ -277,8 +281,10 @@
}, 40);
};
// 识别结束 webSocket返回数据
- webSocketRes(resultData) {
- let jsonData = JSON.parse(resultData);
+ webSocketRes(resultData) {
+
+ let jsonData = JSON.parse(resultData);
+ console.log(JSON.stringify( jsonData))
if (jsonData.data && jsonData.data.result) {
let data = jsonData.data.result;
let str = '';
@@ -306,14 +312,17 @@
}
}
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 {
diff --git a/public/xf_voice/nginx.htaccess b/public/xf_voice/nginx.htaccess
deleted file mode 100644
index e69de29bb..000000000