Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
hublot
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Yoann HOUPERT
hublot
Commits
e7df7352
Commit
e7df7352
authored
Apr 03, 2018
by
Yoann HOUPERT
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use one web socket
parent
32ec84d7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
89 deletions
+52
-89
app.js
app.js
+1
-1
client/robot/robot.js
client/robot/robot.js
+26
-24
lib/proxy.js
lib/proxy.js
+4
-4
lib/resume.js
lib/resume.js
+21
-60
No files found.
app.js
View file @
e7df7352
...
...
@@ -27,7 +27,7 @@ const loader = require('./lib/loader.js')('./client');
const
controllerFactory
=
require
(
'
./lib/controller.js
'
);
const
proxy
=
require
(
'
./lib/proxy.js
'
)(
config
.
proxy
);
const
resumeGenerator
=
require
(
'
./lib/resume.js
'
)(
config
.
offline
)
const
resumeGenerator
=
require
(
'
./lib/resume.js
'
)(
config
.
offline
)
;
console
.
log
(
'
starting hublot...
'
);
...
...
client/robot/robot.js
View file @
e7df7352
...
...
@@ -30,10 +30,11 @@ robot = {
room
:
''
,
clientConfig
:
{},
previousReco
:
[],
recordedParticipantsWS
:
{}
,
recordedParticipantsWS
:
undefined
,
participantsMediaRecorders
:
{},
isDisconnected
:
false
,
intervalList
:
[],
speakerId
:
{},
processAudio
(
stream
,
callback
,
interval
)
{
const
mediaRecorder
=
new
MediaRecorder
(
stream
);
...
...
@@ -90,22 +91,25 @@ robot = {
}
},
openSTTSocket
(
easyrtcid
)
{
const
ws
=
robotLib
.
stt
.
getTranscriptSocket
(
e
=>
{
console
.
log
(
'
>
'
+
e
.
text
);
robotLib
.
reco
.
send
(
{
from
:
robot
.
room
,
text
:
e
.
from
+
'
\t
'
+
e
.
until
+
'
\t
'
+
easyrtcid
+
'
\t
'
+
e
.
text
});
});
ws
.
addEventListener
(
'
error
'
,
e
=>
{
// Try to open new connection on error
console
.
error
(
'
STT ws for
'
+
easyrtcid
+
'
error. Trying to reopen
'
);
console
.
error
(
e
);
robot
.
openSTTSocket
(
easyrtcid
);
});
robot
.
recordedParticipantsWS
[
easyrtcid
]
=
ws
;
openSTTSocket
()
{
if
(
robot
.
recordedParticipantsWS
===
undefined
){
const
ws
=
robotLib
.
stt
.
getTranscriptSocket
(
e
=>
{
console
.
log
(
'
>
'
+
e
.
text
);
robotLib
.
reco
.
send
(
{
from
:
robot
.
room
,
text
:
e
.
from
+
'
\t
'
+
e
.
until
+
'
\t
'
+
speakerId
+
'
\t
'
+
e
.
text
});
});
ws
.
addEventListener
(
'
error
'
,
e
=>
{
// Try to open new connection on error
console
.
error
(
'
STT ws for
'
+
easyrtcid
+
'
error. Trying to reopen
'
);
console
.
error
(
e
);
robot
.
openSTTSocket
();
});
robot
.
recordedParticipantsWS
=
ws
;
}
},
getUserStream
(
easyrtcid
)
{
...
...
@@ -117,12 +121,13 @@ robot = {
},
audioGenerator
(
easyrtcid
,
e
)
{
robot
.
recordedParticipantsWS
[
easyrtcid
].
send
(
e
.
data
);
speakerId
=
easyrtcid
;
robot
.
recordedParticipantsWS
.
send
(
e
.
data
);
},
recordParticipant
(
easyrtcid
)
{
robot
.
openSTTSocket
(
easyrtcid
);
robot
.
openSTTSocket
();
robot
.
getUserStream
(
easyrtcid
);
},
...
...
@@ -130,9 +135,6 @@ robot = {
if
(
robot
.
participantsMediaRecorders
[
easyrtcid
])
{
robot
.
participantsMediaRecorders
[
easyrtcid
].
stop
();
}
if
(
robot
.
recordedParticipantsWS
[
easyrtcid
])
{
robot
.
recordedParticipantsWS
[
easyrtcid
].
close
();
}
},
checkDisconnect
()
{
...
...
@@ -147,7 +149,7 @@ robot = {
}
robot
.
intervalList
=
[];
const
keyMap
=
Object
.
keys
(
robot
.
recordedParticipantsWS
);
const
keyMap
=
Object
.
keys
(
robot
.
participantsMediaRecorders
);
if
(
keyMap
)
{
for
(
let
i
=
0
;
i
<
keyMap
.
length
;
i
++
)
{
try
{
...
...
@@ -156,6 +158,7 @@ robot = {
console
.
log
(
'
This user is inactive
'
);
}
}
robot
.
recordedParticipantsWS
.
close
();
}
},
...
...
@@ -176,7 +179,6 @@ robot = {
};
robotController
.
onAttendeeRemove
=
(
e
,
data
)
=>
{
robot
.
stopRecordParticipant
(
data
.
easyrtcid
);
robot
.
checkDisconnect
();
};
...
...
lib/proxy.js
View file @
e7df7352
...
...
@@ -77,8 +77,8 @@ module.exports = config => {
connectionToClient
.
on
(
'
close
'
,
()
=>
connectionToKaldi
.
close
());
connectionToKaldi
.
on
(
'
close
'
,
()
=>
{
resume
.
endStream
(
streamData
)
connectionToClient
.
close
()
resume
.
endStream
(
streamData
)
;
connectionToClient
.
close
()
;
});
});
}
...
...
@@ -145,8 +145,8 @@ module.exports = config => {
}
return
{
create
:
(
resume
)
=>
{
resume
.
createFolder
()
create
:
resume
=>
{
resume
.
createFolder
()
;
const
server
=
http
.
createServer
();
...
...
lib/resume.js
View file @
e7df7352
...
...
@@ -21,8 +21,7 @@ const fs = require('fs');
const
uuidv1
=
require
(
'
uuid/v1
'
);
const
ffmpegInstaller
=
require
(
'
@ffmpeg-installer/ffmpeg
'
);
const
ffprobeInstaller
=
require
(
'
@ffprobe-installer/ffprobe
'
);
const
ffprobeInstaller
=
require
(
'
@ffprobe-installer/ffprobe
'
);
const
ffmpeg
=
require
(
'
fluent-ffmpeg
'
);
...
...
@@ -32,11 +31,10 @@ ffmpeg.setFfprobePath(ffprobeInstaller.path);
module
.
exports
=
ffmpeg
;
module
.
exports
=
config
=>
{
let
timestamp
=
undefined
;
let
timestamp
;
return
{
createFolder
:
()
=>
{
createFolder
:
()
=>
{
if
(
!
fs
.
existsSync
(
config
.
folder
.
audioRaw
))
{
fs
.
mkdirSync
(
config
.
folder
.
audioRaw
);
}
...
...
@@ -44,71 +42,34 @@ module.exports = config => {
fs
.
mkdirSync
(
config
.
folder
.
audio
);
}
},
generateStream
:
()
=>
{
if
(
timestamp
===
undefined
)
{
timestamp
=
new
Date
().
getTime
()
generateStream
:
()
=>
{
if
(
timestamp
===
undefined
)
{
timestamp
=
new
Date
().
getTime
()
;
}
const
name
=
uuidv1
()
const
path
=
config
.
folder
.
audioRaw
+
"
/
"
+
name
+
"
.wav
"
const
name
=
uuidv1
()
;
const
path
=
config
.
folder
.
audioRaw
+
'
/
'
+
name
+
'
.wav
'
;
const
streamData
=
{
"
wstream
"
:
fs
.
createWriteStream
(
path
),
"
pathFile
"
:
path
,
"
fileName
"
:
name
,
"
timestamp
"
:
new
Date
().
getTime
()
}
return
streamData
wstream
:
fs
.
createWriteStream
(
path
),
pathFile
:
path
,
fileName
:
name
,
timestamp
:
new
Date
().
getTime
()
}
;
return
streamData
;
},
endStream
:
(
streamData
)
=>
{
const
toSecond
=
1000
streamData
.
wstream
.
close
();
let
delay
=
((
timestamp
-
streamData
.
timestamp
)
/
toSecond
)
*
-
1
;
try
{
//var silence = ffmpeg().input('anullsrc=sample_rate=16000').inputFormat('lavfi').duration(delay).output(config.folder.audio+"/silence_"+streamData.fileName+".wav").run();
//var stream = ffmpeg(streamData.pathFile).toFormat(config.audio.format).noVideo().audioBitrate(config.audio.bitrate).audioChannels(config.audio.channels).audioFrequency(config.audio.srate).save(config.folder.audio+"/"+streamData.fileName+".wav")
ffmpeg
()
.
input
(
'
anullsrc=sample_rate=
'
+
config
.
audio
.
srate
)
.
inputFormat
(
'
lavfi
'
)
.
duration
(
delay
)
.
output
(
config
.
folder
.
audio
+
"
/silence_
"
+
streamData
.
fileName
+
"
.wav
"
)
.
on
(
'
end
'
,
function
()
{
ffmpeg
(
streamData
.
pathFile
)
.
toFormat
(
config
.
audio
.
format
)
.
noVideo
()
.
audioBitrate
(
config
.
audio
.
bitrate
)
.
audioChannels
(
config
.
audio
.
channels
)
.
audioFrequency
(
config
.
audio
.
srate
)
.
save
(
config
.
folder
.
audio
+
"
/
"
+
streamData
.
fileName
+
"
.wav
"
)
.
on
(
'
end
'
,
function
()
{
ffmpeg
()
.
input
(
config
.
folder
.
audio
+
"
/silence_
"
+
streamData
.
fileName
+
"
.wav
"
)
.
input
(
config
.
folder
.
audio
+
"
/
"
+
streamData
.
fileName
+
"
.wav
"
)
.
on
(
'
error
'
,
function
(
err
)
{
console
.
log
(
'
An error occurred:
'
+
err
.
message
);
})
.
on
(
'
end
'
,
function
()
{
console
.
log
(
'
Merging finished !
'
);
})
.
mergeToFile
(
config
.
folder
.
audioMerged
+
"
/
"
+
streamData
.
fileName
+
"
.wav
"
,
config
.
folder
.
audio
)
})
})
.
run
()
/*
endStream
:
streamData
=>
{
const
toSecond
=
1000
;
streamData
.
wstream
.
close
();
const
delay
=
((
timestamp
-
streamData
.
timestamp
)
/
toSecond
)
*
-
1
;
try
{
ffmpeg
(
streamData
.
pathFile
)
.
toFormat
(
config
.
audio
.
format
)
.
noVideo
()
.
audioBitrate
(
config
.
audio
.
bitrate
)
.
audioChannels
(
config
.
audio
.
channels
)
.
audioFrequency
(
config
.
audio
.
srate
)
.save(config.folder.audio
+"/"+streamData.fileName+".wav")*/
}
catch
(
err
)
{
.
save
(
config
.
folder
.
audio
+
'
/
'
+
streamData
.
fileName
+
'
.wav
'
);
}
catch
(
err
)
{
// Sometimes, the client will close the connection unexpectedly
// (e.g. when stopping). This is expected
}
...
...
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