1
1
mirror of https://github.com/leon-ai/leon.git synced 2024-12-18 22:31:32 +03:00

refactor(server): keep STT and TTS inside the brain

This commit is contained in:
louistiti 2022-02-13 05:39:17 +08:00
parent f24513a223
commit 18286800ed
No known key found for this signature in database
GPG Key ID: 7ECA3DD523793FE6
2 changed files with 14 additions and 10 deletions

View File

@ -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
}

View File

@ -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)
}