1
1
mirror of https://github.com/leon-ai/leon.git synced 2025-01-03 22:28:10 +03:00

refactor(server): make use of consts for voice config matters

This commit is contained in:
louistiti 2022-09-04 14:10:42 +08:00
parent e07ec87838
commit d05d572b70
No known key found for this signature in database
GPG Key ID: 7ECA3DD523793FE6
4 changed files with 35 additions and 12 deletions

View File

@ -17,3 +17,10 @@ export const HOST = process.env['LEON_HOST']
export const PORT = process.env['LEON_PORT']
export const TIME_ZONE = process.env['LEON_TIME_ZONE']
export const HAS_AFTER_SPEECH = process.env['LEON_AFTER_SPEECH'] === 'true'
export const HAS_STT = process.env['LEON_STT'] === 'true'
export const STT_PROVIDER = process.env['LEON_STT_PROVIDER']
export const HAS_TTS = process.env['LEON_TTS'] === 'true'
export const TTS_PROVIDER = process.env['LEON_TTS_PROVIDER']

View File

@ -3,6 +3,7 @@ import path from 'path'
import { spawn } from 'child_process'
import { langs } from '@@/core/langs.json'
import { HAS_TTS } from '@/constants'
import log from '@/helpers/log'
import string from '@/helpers/string'
import Synchronizer from '@/core/synchronizer'
@ -68,7 +69,7 @@ class Brain {
)
)
if (process.env.LEON_TTS === 'true') {
if (HAS_TTS) {
this._tts.init(this._lang, () => {
log.title('Brain')
log.info('Language has changed')
@ -97,7 +98,7 @@ class Brain {
log.info('Talking...')
if (rawSpeech !== '') {
if (process.env.LEON_TTS === 'true') {
if (HAS_TTS) {
// Stripe HTML to a whitespace. Whitespace to let the TTS respects punctuation
const speech = rawSpeech.replace(/<(?:.|\n)*?>/gm, ' ')

View File

@ -1,4 +1,11 @@
import { version } from '@@/package.json'
import {
HAS_AFTER_SPEECH,
HAS_STT,
HAS_TTS,
STT_PROVIDER,
TTS_PROVIDER
} from '@/constants'
import log from '@/helpers/log'
const getInfo = async (fastify, options) => {
@ -14,15 +21,15 @@ const getInfo = async (fastify, options) => {
status: 200,
code: 'info_pulled',
message,
after_speech: process.env.LEON_AFTER_SPEECH === 'true',
after_speech: HAS_AFTER_SPEECH,
logger: process.env.LEON_LOGGER === 'true',
stt: {
enabled: process.env.LEON_STT === 'true',
provider: process.env.LEON_STT_PROVIDER
enabled: HAS_STT,
provider: STT_PROVIDER
},
tts: {
enabled: process.env.LEON_TTS === 'true',
provider: process.env.LEON_TTS_PROVIDER
enabled: HAS_TTS,
provider: TTS_PROVIDER
},
version
})

View File

@ -5,6 +5,15 @@ import { join } from 'path'
import { version } from '@@/package.json'
import { endpoints } from '@@/core/skills-endpoints.json'
import {
HAS_STT,
HAS_TTS,
HOST,
IS_DEVELOPMENT_ENV,
PORT,
STT_PROVIDER,
TTS_PROVIDER
} from '@/constants'
import Nlu from '@/core/nlu'
import Brain from '@/core/brain'
import Asr from '@/core/asr'
@ -17,7 +26,6 @@ import infoPlugin from '@/core/http-server/api/info'
import downloadsPlugin from '@/core/http-server/api/downloads'
import log from '@/helpers/log'
import date from '@/helpers/date'
import { HOST, IS_DEVELOPMENT_ENV, PORT } from '@/constants'
const server = {}
@ -229,16 +237,16 @@ server.handleOnConnection = (socket) => {
provider.brain.socket = socket
/* istanbul ignore if */
if (process.env.LEON_STT === 'true') {
if (HAS_STT) {
sttState = 'enabled'
provider.brain.stt = new Stt(socket, process.env.LEON_STT_PROVIDER)
provider.brain.stt = new Stt(socket, STT_PROVIDER)
provider.brain.stt.init(() => null)
}
if (process.env.LEON_TTS === 'true') {
if (HAS_TTS) {
ttsState = 'enabled'
provider.brain.tts = new Tts(socket, process.env.LEON_TTS_PROVIDER)
provider.brain.tts = new Tts(socket, TTS_PROVIDER)
provider.brain.tts.init('en', () => null)
}