Toggle navigation
Toggle navigation
This project
Loading...
Sign in
이준성
/
khuwitch
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Jinsu Park
2020-12-08 19:26:40 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
5cd3143da93ebe7df264c9dc6769f05b0d41858b
5cd3143d
1 parent
3151102f
Update: tts로 변환 후 음성을 재생할 때 Queue를 이용해 한 음성씩 재생
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
9 deletions
frontend/src/Channel.js
frontend/src/tts.js
frontend/src/Channel.js
View file @
5cd3143
...
...
@@ -8,6 +8,9 @@ import { WatchOutlined } from "@material-ui/icons";
import
io
from
'socket.io-client'
import
tts
from
'./tts'
;
// audioQueue에서 하나씩 뽑아서 재생한다.
tts
.
enableAudio
()
const
socket
=
io
.
connect
(
"http://localhost:3303"
)
socket
.
on
(
"connect"
,
event
=>
{
// 테스트용으로 umi0410에게 입장.
...
...
@@ -19,7 +22,8 @@ socket.on("connect", event=>{
socket
.
on
(
'chat message'
,
(
name
,
msg
)
=>
{
console
.
log
(
msg
)
console
.
log
(
"got message"
)
tts
.
speak
(
msg
)
//tts를 audio로 변경해 audioQueue에 집어넣는다.
tts
.
enqueueTTS
(
msg
)
})
// 해당 채널을 재생하고자할 때 실행시켜주세요.
...
...
frontend/src/tts.js
View file @
5cd3143
...
...
@@ -7,7 +7,29 @@ const polly = new AWS.Polly({
region
:
'ap-northeast-2'
,
});
function
speak
(
text
){
const
audioQueue
=
[]
// test data
// const audioQueue = ["https://file-examples-com.github.io/uploads/2017/11/file_example_MP3_700KB.mp3", "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3", "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-2.mp3"]
const
audio
=
new
Audio
()
// queue에서 작업(재생할 내용)을 0.5초마다 폴링하는 방식
function
enableAudio
(){
setInterval
(()
=>
{
// 앞선 tts 재생이 종료된 경우에만 새 tts를 실행
if
(
!
audio
.
paused
){
return
;}
let
audioFile
=
audioQueue
.
shift
()
// 재생할 게 있으면 재생
if
(
audioFile
){
console
.
log
(
audioFile
)
audio
.
setAttribute
(
"src"
,
audioFile
)
audio
.
play
()
}
},
500
)
}
function
enqueueTTS
(
text
){
let
params
=
{
'Text'
:
text
,
'OutputFormat'
:
'mp3'
,
...
...
@@ -19,15 +41,17 @@ function speak(text){
tts
.
getSynthesizeSpeechUrl
(
params
,
function
(
error
,
url
)
{
if
(
error
)
{
}
else
{
setTimeout
(()
=>
{
console
.
log
(
"실행"
)
let
audio
=
new
Audio
(
url
)
audio
.
play
()
// .then(delete audio);
},
3000
)
audioQueue
.
push
(
url
)
}
})
}
console
.
log
(
"테스트용 TTS 데이터를 주입합니다."
)
enqueueTTS
(
"복잡한 브랜치"
)
enqueueTTS
(
"빵상 아주머니는 말씀하셨다."
)
enqueueTTS
(
"니가가라 하와이"
)
export
default
{
"speak"
:
speak
,
enableAudio
,
enqueueTTS
,
}
...
...
Please
register
or
login
to post a comment