From 18286800edc1a3a1dce4e5503caffe52125acf65 Mon Sep 17 00:00:00 2001 From: louistiti Date: Sun, 13 Feb 2022 05:39:17 +0800 Subject: [PATCH] refactor(server): keep STT and TTS inside the brain --- server/src/core/brain.js | 9 +++++++++ server/src/core/http-server/server.js | 15 +++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/server/src/core/brain.js b/server/src/core/brain.js index 7f9102f3..b203d67e 100644 --- a/server/src/core/brain.js +++ b/server/src/core/brain.js @@ -15,6 +15,7 @@ class Brain { this.interOutput = { } this.finalOutput = { } this._socket = { } + this._stt = { } this._tts = { } log.title('Brain') @@ -29,6 +30,14 @@ class Brain { this._socket = newSocket } + get stt () { + return this._stt + } + + set stt (newStt) { + this._stt = newStt + } + get tts () { return this._tts } diff --git a/server/src/core/http-server/server.js b/server/src/core/http-server/server.js index c8f7e5f8..d289639a 100644 --- a/server/src/core/http-server/server.js +++ b/server/src/core/http-server/server.js @@ -146,8 +146,6 @@ server.handleOnConnection = (socket) => { }) } else { const asr = new Asr() - let stt = { } - let tts = { } let sttState = 'disabled' let ttsState = 'disabled' @@ -157,17 +155,14 @@ server.handleOnConnection = (socket) => { if (process.env.LEON_STT === 'true') { sttState = 'enabled' - stt = new Stt(socket, process.env.LEON_STT_PROVIDER) - stt.init(() => null) + brain.stt = new Stt(socket, process.env.LEON_STT_PROVIDER) + brain.stt.init(() => null) } - if (process.env.LEON_TTS === 'true') { ttsState = 'enabled' - tts = new Tts(socket, process.env.LEON_TTS_PROVIDER) - tts.init('en', (ttsInstance) => { - brain.tts = ttsInstance - }) + brain.tts = new Tts(socket, process.env.LEON_TTS_PROVIDER) + brain.tts.init('en', () => null) } log.title('Initialization') @@ -186,7 +181,7 @@ server.handleOnConnection = (socket) => { // Handle automatic speech recognition socket.on('recognize', async (data) => { try { - await asr.run(data, stt) + await asr.run(data, brain.stt) } catch (e) { log[e.type](e.obj.message) }