Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
H
huamu
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
郭铭瑶
huamu
Commits
96a3fd57
Commit
96a3fd57
authored
Oct 21, 2021
by
郭铭瑶
🤘
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
调整语音输入
parent
4845ee9c
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
12 deletions
+63
-12
transcode.worker.js
public/transcode.worker.js
+43
-0
iat-recorder.js
src/util/iat-recorder.js
+10
-6
new-activity-drawer.vue
src/view/components/new-activity-drawer.vue
+10
-6
No files found.
public/transcode.worker.js
0 → 100644
View file @
96a3fd57
;(
function
()
{
const
self
=
this
self
.
onmessage
=
function
(
e
)
{
transAudioData
.
transcode
(
e
.
data
)
}
const
transAudioData
=
{
transcode
(
audioData
)
{
let
output
=
transAudioData
.
to16kHz
(
audioData
)
output
=
transAudioData
.
to16BitPCM
(
output
)
output
=
Array
.
from
(
new
Uint8Array
(
output
.
buffer
))
self
.
postMessage
(
output
)
// return output
},
to16kHz
(
audioData
)
{
const
data
=
new
Float32Array
(
audioData
)
const
fitCount
=
Math
.
round
(
data
.
length
*
(
16000
/
44100
))
const
newData
=
new
Float32Array
(
fitCount
)
const
springFactor
=
(
data
.
length
-
1
)
/
(
fitCount
-
1
)
newData
[
0
]
=
data
[
0
]
for
(
let
i
=
1
;
i
<
fitCount
-
1
;
i
++
)
{
const
tmp
=
i
*
springFactor
const
before
=
Math
.
floor
(
tmp
).
toFixed
()
const
after
=
Math
.
ceil
(
tmp
).
toFixed
()
const
atPoint
=
tmp
-
before
newData
[
i
]
=
data
[
before
]
+
(
data
[
after
]
-
data
[
before
])
*
atPoint
}
newData
[
fitCount
-
1
]
=
data
[
data
.
length
-
1
]
return
newData
},
to16BitPCM
(
input
)
{
const
dataLength
=
input
.
length
*
(
16
/
8
)
const
dataBuffer
=
new
ArrayBuffer
(
dataLength
)
const
dataView
=
new
DataView
(
dataBuffer
)
let
offset
=
0
for
(
let
i
=
0
;
i
<
input
.
length
;
i
++
,
offset
+=
2
)
{
const
s
=
Math
.
max
(
-
1
,
Math
.
min
(
1
,
input
[
i
]))
dataView
.
setInt16
(
offset
,
s
<
0
?
s
*
0x8000
:
s
*
0x7fff
,
true
)
}
return
dataView
},
}
})()
src/util/iat-recorder.js
View file @
96a3fd57
import
CryptoJS
from
'crypto-js'
const
worker
=
process
.
env
.
NODE_ENV
===
'production'
?
'./transcode.worker.js'
:
'/transcode.worker.js'
const
transWorker
=
new
Worker
(
'./transcode.worker.js'
)
const
APPID
=
'4f3360ec'
const
API_SECRET
=
'ODQ2ZDAyYTg3ZjVhMWQyMWJhYjUxNWQ3'
...
...
@@ -87,10 +91,10 @@ export default class IatRecorder {
this
.
result
(
e
.
data
)
}
iatWS
.
onerror
=
(
e
)
=>
{
this
.
recorderStop
(
'end'
)
this
.
recorderStop
()
}
iatWS
.
onclose
=
(
e
)
=>
{
this
.
recorderStop
(
'end'
)
this
.
recorderStop
()
}
})
}
...
...
@@ -197,7 +201,7 @@ export default class IatRecorder {
}
}
// 暂停录音
recorderStop
(
status
)
{
recorderStop
()
{
// safari下suspend后再次resume录音内容将是空白,设置safari下不做suspend
if
(
!
(
...
...
@@ -206,7 +210,7 @@ export default class IatRecorder {
)
{
this
.
audioContext
&&
this
.
audioContext
.
suspend
()
}
this
.
setStatus
(
status
)
this
.
setStatus
(
'end'
)
}
// 处理音频数据
// transAudioData(audioData) {
...
...
@@ -237,7 +241,7 @@ export default class IatRecorder {
language
:
this
.
language
,
//小语种可在控制台--语音听写(流式)--方言/语种处添加试用
domain
:
'iat'
,
accent
:
this
.
accent
,
//中文方言可在控制台--语音听写(流式)--方言/语种处添加试用
vad_eos
:
2
000
,
vad_eos
:
3
000
,
dwa
:
'wpgs'
,
//为使该功能生效,需到控制台开通动态修正功能(该功能免费)
ptt
:
1
,
},
...
...
@@ -330,6 +334,6 @@ export default class IatRecorder {
this
.
setResultText
({
resultText
:
''
,
resultTextTemp
:
''
})
}
stop
()
{
this
.
recorderStop
(
'stop'
)
this
.
recorderStop
()
}
}
src/view/components/new-activity-drawer.vue
View file @
96a3fd57
...
...
@@ -253,7 +253,7 @@
:class=
"{ recording: status === 'ing' }"
@
click=
"toggleRecorder"
>
{{ status === 'ing' ? '
停止输入
' : '语音输入' }}
{{ status === 'ing' ? '
输入中…
' : '语音输入' }}
</n-button>
</n-form-item-gi>
<n-form-item-gi
...
...
@@ -343,20 +343,24 @@ import useVoiceRecorder from '@/hooks/useVoiceRecorder'
const
{
result
,
toggleRecorder
,
status
,
resetRecorder
}
=
useVoiceRecorder
()
const
activityDescribtion
=
ref
(
''
)
watch
([()
=>
result
.
value
,
()
=>
status
.
value
],
([
txt
,
sta
])
=>
{
console
.
log
(
sta
,
txt
)
if
(
!
txt
)
return
if
(
sta
===
'end'
)
{
activityDescribtion
.
value
=
detailData
.
value
.
attachment
}
else
{
if
(
activityDescribtion
.
value
)
{
detailData
.
value
.
attachment
=
activityDescribtion
.
value
+
txt
}
else
{
detailData
.
value
.
attachment
=
txt
}
if
(
sta
===
'end'
)
{
activityDescribtion
.
value
=
detailData
.
value
.
attachment
}
})
function
onInput
(
val
)
{
if
(
!
val
)
{
activityDescribtion
.
value
=
''
resetRecorder
()
}
activityDescribtion
.
value
=
val
}
const
message
=
useMessage
()
const
props
=
defineProps
({
...
...
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