Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
C
CharIP-Electron
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
ali
CharIP-Electron
Commits
36619ae0
Commit
36619ae0
authored
Dec 05, 2023
by
ali
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:删除多余文件
parent
fec7d389
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
48 additions
and
151 deletions
+48
-151
vosk-model-small-ca-0.4.tar.gz
...enderer/public/vosk/models/vosk-model-small-ca-0.4.tar.gz
+0
-0
vosk-model-small-de-0.15.tar.gz
...nderer/public/vosk/models/vosk-model-small-de-0.15.tar.gz
+0
-0
vosk-model-small-es-0.3.tar.gz
...enderer/public/vosk/models/vosk-model-small-es-0.3.tar.gz
+0
-0
vosk-model-small-fa-0.4.tar.gz
...enderer/public/vosk/models/vosk-model-small-fa-0.4.tar.gz
+0
-0
vosk-model-small-fr-pguyot-0.3.tar.gz
.../public/vosk/models/vosk-model-small-fr-pguyot-0.3.tar.gz
+0
-0
vosk-model-small-it-0.4.tar.gz
...enderer/public/vosk/models/vosk-model-small-it-0.4.tar.gz
+0
-0
vosk-model-small-pt-0.3.tar.gz
...enderer/public/vosk/models/vosk-model-small-pt-0.3.tar.gz
+0
-0
vosk-model-small-ru-0.4.tar.gz
...enderer/public/vosk/models/vosk-model-small-ru-0.4.tar.gz
+0
-0
vosk-model-small-tr-0.3.tar.gz
...enderer/public/vosk/models/vosk-model-small-tr-0.3.tar.gz
+0
-0
vosk-model-small-vn-0.3.tar.gz
...enderer/public/vosk/models/vosk-model-small-vn-0.3.tar.gz
+0
-0
voice_client_with_script_processor.js
...enderer/public/vosk/voice_client_with_script_processor.js
+0
-103
ShowVideo.vue
src/renderer/screens/ShowVideo.vue
+48
-48
No files found.
src/renderer/public/vosk/models/vosk-model-small-ca-0.4.tar.gz
deleted
100644 → 0
View file @
fec7d389
File deleted
src/renderer/public/vosk/models/vosk-model-small-de-0.15.tar.gz
deleted
100644 → 0
View file @
fec7d389
File deleted
src/renderer/public/vosk/models/vosk-model-small-es-0.3.tar.gz
deleted
100644 → 0
View file @
fec7d389
File deleted
src/renderer/public/vosk/models/vosk-model-small-fa-0.4.tar.gz
deleted
100644 → 0
View file @
fec7d389
File deleted
src/renderer/public/vosk/models/vosk-model-small-fr-pguyot-0.3.tar.gz
deleted
100644 → 0
View file @
fec7d389
File deleted
src/renderer/public/vosk/models/vosk-model-small-it-0.4.tar.gz
deleted
100644 → 0
View file @
fec7d389
File deleted
src/renderer/public/vosk/models/vosk-model-small-pt-0.3.tar.gz
deleted
100644 → 0
View file @
fec7d389
File deleted
src/renderer/public/vosk/models/vosk-model-small-ru-0.4.tar.gz
deleted
100644 → 0
View file @
fec7d389
File deleted
src/renderer/public/vosk/models/vosk-model-small-tr-0.3.tar.gz
deleted
100644 → 0
View file @
fec7d389
File deleted
src/renderer/public/vosk/models/vosk-model-small-vn-0.3.tar.gz
deleted
100644 → 0
View file @
fec7d389
File deleted
src/renderer/public/vosk/voice_client_with_script_processor.js
deleted
100644 → 0
View file @
fec7d389
var
context
;
var
source
;
var
processor
;
var
streamLocal
;
var
webSocket
;
var
inputArea
;
var
bufferSize
=
8192
;
var
sampleRate
=
8000
;
var
wsURL
=
'ws://10.90.120.27:2700'
;
var
initComplete
=
false
;
;(
function
()
{
document
.
addEventListener
(
'DOMContentLoaded'
,
(
event
)
=>
{
inputArea
=
document
.
getElementById
(
'q'
);
const
listenButton
=
document
.
getElementById
(
'listenWithScript'
);
const
stopListeningButton
=
document
.
getElementById
(
'stopListeningWithScript'
);
listenButton
.
addEventListener
(
'mousedown'
,
function
()
{
listenButton
.
disabled
=
true
;
initWS
();
navigator
.
mediaDevices
.
getUserMedia
({
audio
:
{
echoCancellation
:
true
,
noiseSuppression
:
true
,
channelCount
:
1
,
sampleRate
},
video
:
false
}).
then
(
handleSuccess
);
listenButton
.
style
.
color
=
'green'
;
initComplete
=
true
;
});
stopListeningButton
.
addEventListener
(
'mouseup'
,
function
()
{
if
(
initComplete
===
true
)
{
webSocket
.
send
(
'{"eof" : 1}'
);
webSocket
.
close
();
source
.
disconnect
(
processor
);
processor
.
disconnect
(
context
.
destination
);
if
(
streamLocal
.
active
)
{
streamLocal
.
getTracks
()[
0
].
stop
();
}
listenButton
.
style
.
color
=
'black'
;
listenButton
.
disabled
=
false
;
initComplete
=
false
;
inputArea
.
innerText
=
""
}
});
});
}())
var
handleSuccess
=
function
(
stream
)
{
streamLocal
=
stream
;
context
=
new
AudioContext
({
sampleRate
:
sampleRate
});
source
=
context
.
createMediaStreamSource
(
stream
);
processor
=
context
.
createScriptProcessor
();
source
.
connect
(
processor
);
processor
.
connect
(
context
.
destination
);
processor
.
onaudioprocess
=
function
(
audioDataChunk
)
{
console
.
log
(
audioDataChunk
.
inputBuffer
);
sendAudio
(
audioDataChunk
);
};
};
function
sendAudio
(
audioDataChunk
)
{
if
(
webSocket
.
readyState
===
WebSocket
.
OPEN
)
{
// convert to 16-bit payload
const
inputData
=
audioDataChunk
.
inputBuffer
.
getChannelData
(
0
)
||
new
Float32Array
(
bufferSize
);
const
targetBuffer
=
new
Int16Array
(
inputData
.
length
);
for
(
let
index
=
inputData
.
length
;
index
>
0
;
index
--
)
{
targetBuffer
[
index
]
=
32767
*
Math
.
min
(
1
,
inputData
[
index
]);
}
webSocket
.
send
(
targetBuffer
.
buffer
);
}
}
function
initWS
()
{
webSocket
=
new
WebSocket
(
wsURL
);
webSocket
.
binaryType
=
"arraybuffer"
;
webSocket
.
onopen
=
function
(
event
)
{
console
.
log
(
'New connection established'
);
};
webSocket
.
onerror
=
function
(
event
)
{
console
.
error
(
event
.
data
);
};
webSocket
.
onmessage
=
function
(
event
)
{
if
(
event
.
data
)
{
let
parsed
=
JSON
.
parse
(
event
.
data
);
if
(
parsed
.
partial
&&
parsed
.
partial
!==
'the'
)
inputArea
.
innerText
=
parsed
.
partial
+
'|'
;
if
(
parsed
.
result
)
console
.
log
(
parsed
.
result
);
if
(
parsed
.
text
)
inputArea
.
innerText
=
parsed
.
text
;
}
};
}
src/renderer/screens/ShowVideo.vue
View file @
36619ae0
...
...
@@ -15,7 +15,7 @@ const router = useRouter()
const
route
=
useRoute
()
const
{
settings
,
video
:
useVideo
}
=
useStore
()
let
sampleRate
=
48000
const
bufferSize
=
8192
;
const
bufferSize
=
8192
const
iconMicrophone
=
new
URL
(
'/images/microphone-input.svg'
,
import
.
meta
.
url
).
href
const
recordVolume
=
ref
(
0
)
...
...
@@ -169,21 +169,22 @@ async function startVoskWsAudioInput() {
initVoskWS
()
sampleRate
=
8000
const
mediaStream
=
await
navigator
.
mediaDevices
.
getUserMedia
({
audio
:
{
echoCancellation
:
true
,
noiseSuppression
:
true
,
channelCount
:
1
,
sampleRate
},
video
:
false
});
const
audioContext
=
new
AudioContext
({
sampleRate
});
const
source
=
audioContext
.
createMediaStreamSource
(
mediaStream
);
const
processor
=
audioContext
.
createScriptProcessor
();
source
.
connect
(
processor
);
processor
.
connect
(
audioContext
.
destination
);
processor
.
onaudioprocess
=
(
audioDataChunk
)
=>
postAudio
(
audioDataChunk
);
audio
:
{
echoCancellation
:
true
,
noiseSuppression
:
true
,
channelCount
:
1
,
sampleRate
},
video
:
false
})
const
audioContext
=
new
AudioContext
({
sampleRate
})
const
source
=
audioContext
.
createMediaStreamSource
(
mediaStream
)
const
processor
=
audioContext
.
createScriptProcessor
()
source
.
connect
(
processor
)
processor
.
connect
(
audioContext
.
destination
)
processor
.
onaudioprocess
=
(
audioDataChunk
)
=>
postAudio
(
audioDataChunk
)
await
analyzeMicrophoneVolume
(
mediaStream
,
(
val
)
=>
{
recordVolume
.
value
=
val
...
...
@@ -196,42 +197,42 @@ async function startVoskWsAudioInput() {
}
function
postAudio
(
audioDataChunk
)
{
if
(
!
inputContext
.
voskWs
)
return
;
if
(
inputContext
.
voskWs
.
readyState
===
WebSocket
.
OPEN
)
{
const
inputData
=
audioDataChunk
.
inputBuffer
.
getChannelData
(
0
)
||
new
Float32Array
(
bufferSize
);
const
targetBuffer
=
new
Int16Array
(
inputData
.
length
);
for
(
let
index
=
inputData
.
length
;
index
>
0
;
index
--
)
{
targetBuffer
[
index
]
=
32767
*
Math
.
min
(
1
,
inputData
[
index
]);
}
inputContext
.
voskWs
.
send
(
targetBuffer
.
buffer
);
if
(
!
inputContext
.
voskWs
)
return
if
(
inputContext
.
voskWs
.
readyState
===
WebSocket
.
OPEN
)
{
const
inputData
=
audioDataChunk
.
inputBuffer
.
getChannelData
(
0
)
||
new
Float32Array
(
bufferSize
)
const
targetBuffer
=
new
Int16Array
(
inputData
.
length
)
for
(
let
index
=
inputData
.
length
;
index
>
0
;
index
--
)
{
targetBuffer
[
index
]
=
32767
*
Math
.
min
(
1
,
inputData
[
index
])
}
inputContext
.
voskWs
.
send
(
targetBuffer
.
buffer
)
}
}
function
initVoskWS
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
inputContext
.
voskWs
=
new
WebSocket
(
settings
.
voskWsLUrl
)
;
inputContext
.
voskWs
.
binaryType
=
"arraybuffer"
;
inputContext
.
asrPartial
=
''
;
inputContext
.
voskWs
=
new
WebSocket
(
settings
.
voskWsLUrl
)
inputContext
.
voskWs
.
binaryType
=
'arraybuffer'
inputContext
.
asrPartial
=
''
inputContext
.
voskWs
.
onopen
=
function
(
event
)
{
resolve
(
inputContext
.
voskWs
)
;
}
;
resolve
(
inputContext
.
voskWs
)
}
inputContext
.
voskWs
.
onerror
=
function
(
event
)
{
reject
(
new
Error
(
JSON
.
stringify
(
event
)))
}
;
}
inputContext
.
voskWs
.
onmessage
=
function
(
event
)
{
if
(
!
event
.
data
)
return
const
parsed
=
JSON
.
parse
(
event
.
data
)
;
if
(
parsed
.
partial
&&
parsed
.
partial
!==
'the'
)
inputContext
.
asrPartial
=
parsed
.
partial
+
'|'
;
const
parsed
=
JSON
.
parse
(
event
.
data
)
if
(
parsed
.
partial
&&
parsed
.
partial
!==
'the'
)
inputContext
.
asrPartial
=
parsed
.
partial
+
'|'
// if (parsed.result) console.log(parsed.result);
if
(
parsed
.
text
)
{
inputContext
.
asrPartial
=
parsed
.
text
;
onAsr
(
inputContext
.
asrPartial
)
;
}
;
}
;
inputContext
.
asrPartial
=
parsed
.
text
onAsr
(
inputContext
.
asrPartial
)
}
}
})
}
...
...
@@ -243,14 +244,14 @@ function endAudioInput() {
inputContext
.
scriptProcessorNode
&&
(
inputContext
.
scriptProcessorNode
.
onaudioprocess
=
null
)
inputContext
.
model
?.
terminate
()
if
(
inputContext
.
voskWs
)
{
inputContext
.
voskWs
.
send
(
'{"eof" : 1}'
)
;
inputContext
.
voskWs
.
close
()
;
inputContext
.
voskWs
.
send
(
'{"eof" : 1}'
)
inputContext
.
voskWs
.
close
()
}
}
function
setVideoUrl
(
url
:
string
)
{
const
videoEle
=
videoElement
.
value
as
HTMLVideoElement
if
(
!
videoEle
)
return
;
if
(
!
videoEle
)
return
videoEle
.
src
=
url
videoEle
.
load
()
...
...
@@ -268,10 +269,10 @@ async function onAsr(question: string) {
console
.
log
(
question
+
' : '
+
q
)
if
(
q
.
includes
(
question
))
{
const
videoEle
=
videoElement
.
value
as
HTMLVideoElement
videoEle
&&
(
videoEle
.
loop
=
false
)
;
videoEle
&&
(
videoEle
.
muted
=
false
)
;
setVideoUrl
(
url
)
;
return
;
videoEle
&&
(
videoEle
.
loop
=
false
)
videoEle
&&
(
videoEle
.
muted
=
false
)
setVideoUrl
(
url
)
return
}
}
...
...
@@ -322,7 +323,6 @@ async function onAsr(question: string) {
console
.
log
(
'----------------> Asr:'
,
question
)
ws
.
send
(
JSON
.
stringify
({
prompt
:
question
,
historys_list
:
[]
}))
}
function
initLLMSocket
():
Promise
<
WebSocket
>
{
...
...
@@ -378,9 +378,9 @@ async function runAudioPlay() {
audio
.
onended
=
()
=>
{
isPlayRunning
=
false
const
videoEle
=
videoElement
.
value
as
HTMLVideoElement
videoEle
&&
(
videoEle
.
loop
=
true
)
;
videoEle
&&
(
videoEle
.
muted
=
true
)
;
setVideoUrl
(
new
URL
(
'/libai/10.mp4'
,
import
.
meta
.
url
).
href
)
;
videoEle
&&
(
videoEle
.
loop
=
true
)
videoEle
&&
(
videoEle
.
muted
=
true
)
setVideoUrl
(
new
URL
(
'/libai/10.mp4'
,
import
.
meta
.
url
).
href
)
runAudioPlay
()
}
await
audio
.
play
()
...
...
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