Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
CivWeb
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ReactWeb5
CivWeb
Commits
33bc366c
Commit
33bc366c
authored
Mar 14, 2024
by
xuchaozou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 优化加载页速度
parent
360a03af
Pipeline
#86021
passed with stages
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
4 deletions
+15
-4
PandaRecordWebSocket.js
...ponents/SoundAi/core/core/sockets/PandaRecordWebSocket.js
+3
-4
Utils.js
src/components/SoundAi/core/utils/Utils.js
+12
-0
No files found.
src/components/SoundAi/core/core/sockets/PandaRecordWebSocket.js
View file @
33bc366c
...
...
@@ -146,7 +146,6 @@ class PandaRecordWebSocket extends PandaWebSocket {
if
([
this
.
ws
.
CONNECTING
,
this
.
ws
.
OPEN
].
includes
(
this
.
ws
.
readyState
))
{
this
.
frameBuffers
.
push
(
frameBuffer
)
}
else
if
(
this
.
ws
.
CLOSED
==
this
.
ws
.
readyState
){
this
.
frameBuffers
.
push
(
frameBuffer
)
this
.
ws
=
null
}
}
...
...
@@ -183,18 +182,18 @@ class PandaRecordWebSocket extends PandaWebSocket {
this
.
time
=
setInterval
(
function
()
{
if
(
!
this
.
ws
)
return
if
(
this
.
ws
.
readyState
!=
this
.
ws
.
OPEN
)
return
const
frameBuffer
=
this
.
frameBuffers
.
shift
()
if
(
!
frameBuffer
)
return
if
(
this
.
frameBuffers
.
length
==
0
)
return
this
.
ws
.
send
(
JSON
.
stringify
({
data
:
{
format
,
encoding
,
status
:
1
,
audio
:
Utils
.
toBase64
(
frameBuffer
),
audio
:
Utils
.
toBase64
(
Utils
.
mergeArrayBuffers
(
this
.
frameBuffers
)
),
},
})
)
this
.
frameBuffers
=
[]
}.
bind
(
this
),
40
)
}
...
...
src/components/SoundAi/core/utils/Utils.js
View file @
33bc366c
...
...
@@ -15,6 +15,18 @@ const Utils = {
},
time
);
});
},
mergeArrayBuffers
(
buffers
)
{
if
(
buffers
.
length
==
1
)
return
buffers
[
0
]
const
byteLength
=
buffers
.
reduce
((
prev
,
cur
)
=>
prev
+
cur
.
byteLength
,
0
)
const
mergeBuffer
=
new
ArrayBuffer
(
byteLength
)
const
mergeView
=
new
Uint8Array
(
mergeBuffer
)
let
offset
=
0
for
(
let
i
=
0
;
i
<
buffers
.
length
;
i
++
)
{
mergeView
.
set
(
new
Uint8Array
(
buffers
[
i
]),
offset
)
offset
+=
buffers
[
i
].
byteLength
}
return
mergeBuffer
},
getMediaCodeToMsg
(
code
)
{
if
(
/device not found/
.
test
(
code
))
{
return
'没有发现录音设备'
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment