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:
parent
f24513a223
commit
18286800ed
@ -15,6 +15,7 @@ class Brain {
|
|||||||
this.interOutput = { }
|
this.interOutput = { }
|
||||||
this.finalOutput = { }
|
this.finalOutput = { }
|
||||||
this._socket = { }
|
this._socket = { }
|
||||||
|
this._stt = { }
|
||||||
this._tts = { }
|
this._tts = { }
|
||||||
|
|
||||||
log.title('Brain')
|
log.title('Brain')
|
||||||
@ -29,6 +30,14 @@ class Brain {
|
|||||||
this._socket = newSocket
|
this._socket = newSocket
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get stt () {
|
||||||
|
return this._stt
|
||||||
|
}
|
||||||
|
|
||||||
|
set stt (newStt) {
|
||||||
|
this._stt = newStt
|
||||||
|
}
|
||||||
|
|
||||||
get tts () {
|
get tts () {
|
||||||
return this._tts
|
return this._tts
|
||||||
}
|
}
|
||||||
|
@ -146,8 +146,6 @@ server.handleOnConnection = (socket) => {
|
|||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
const asr = new Asr()
|
const asr = new Asr()
|
||||||
let stt = { }
|
|
||||||
let tts = { }
|
|
||||||
let sttState = 'disabled'
|
let sttState = 'disabled'
|
||||||
let ttsState = 'disabled'
|
let ttsState = 'disabled'
|
||||||
|
|
||||||
@ -157,17 +155,14 @@ server.handleOnConnection = (socket) => {
|
|||||||
if (process.env.LEON_STT === 'true') {
|
if (process.env.LEON_STT === 'true') {
|
||||||
sttState = 'enabled'
|
sttState = 'enabled'
|
||||||
|
|
||||||
stt = new Stt(socket, process.env.LEON_STT_PROVIDER)
|
brain.stt = new Stt(socket, process.env.LEON_STT_PROVIDER)
|
||||||
stt.init(() => null)
|
brain.stt.init(() => null)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.env.LEON_TTS === 'true') {
|
if (process.env.LEON_TTS === 'true') {
|
||||||
ttsState = 'enabled'
|
ttsState = 'enabled'
|
||||||
|
|
||||||
tts = new Tts(socket, process.env.LEON_TTS_PROVIDER)
|
brain.tts = new Tts(socket, process.env.LEON_TTS_PROVIDER)
|
||||||
tts.init('en', (ttsInstance) => {
|
brain.tts.init('en', () => null)
|
||||||
brain.tts = ttsInstance
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.title('Initialization')
|
log.title('Initialization')
|
||||||
@ -186,7 +181,7 @@ server.handleOnConnection = (socket) => {
|
|||||||
// Handle automatic speech recognition
|
// Handle automatic speech recognition
|
||||||
socket.on('recognize', async (data) => {
|
socket.on('recognize', async (data) => {
|
||||||
try {
|
try {
|
||||||
await asr.run(data, stt)
|
await asr.run(data, brain.stt)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log[e.type](e.obj.message)
|
log[e.type](e.obj.message)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user