From 3713521b08614523b17c4696c5bfd2df084bc73c Mon Sep 17 00:00:00 2001 From: louistiti Date: Sun, 19 Jun 2022 23:57:36 +0800 Subject: [PATCH] refactor: move up /server/src/config to /core level --- .gitignore | 2 +- .../config/synchronizer/google-drive.sample.json | 0 {server/src => core}/config/voice/amazon.sample.json | 0 .../src => core}/config/voice/google-cloud.sample.json | 0 {server/src => core}/config/voice/watson-stt.sample.json | 0 {server/src => core}/config/voice/watson-tts.sample.json | 0 scripts/check.js | 8 ++++---- server/src/core/synchronizer.js | 3 ++- server/src/stt/google-cloud-stt/parser.js | 3 ++- server/src/stt/stt.js | 5 +++-- server/src/stt/watson-stt/parser.js | 3 ++- server/src/tts/amazon-polly/synthesizer.js | 3 ++- server/src/tts/google-cloud-tts/synthesizer.js | 3 ++- server/src/tts/tts.js | 5 +++-- server/src/tts/watson-tts/synthesizer.js | 3 ++- 15 files changed, 23 insertions(+), 15 deletions(-) rename {server/src => core}/config/synchronizer/google-drive.sample.json (100%) rename {server/src => core}/config/voice/amazon.sample.json (100%) rename {server/src => core}/config/voice/google-cloud.sample.json (100%) rename {server/src => core}/config/voice/watson-stt.sample.json (100%) rename {server/src => core}/config/voice/watson-tts.sample.json (100%) diff --git a/.gitignore b/.gitignore index c521282b..6e3ee9d4 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,7 @@ test/coverage/ bridges/python/.venv/* downloads/* logs/* -server/src/config/**/*.json +core/config/**/*.json bin/coqui/* bin/flite/* diff --git a/server/src/config/synchronizer/google-drive.sample.json b/core/config/synchronizer/google-drive.sample.json similarity index 100% rename from server/src/config/synchronizer/google-drive.sample.json rename to core/config/synchronizer/google-drive.sample.json diff --git a/server/src/config/voice/amazon.sample.json b/core/config/voice/amazon.sample.json similarity index 100% rename from server/src/config/voice/amazon.sample.json rename to core/config/voice/amazon.sample.json diff --git a/server/src/config/voice/google-cloud.sample.json b/core/config/voice/google-cloud.sample.json similarity index 100% rename from server/src/config/voice/google-cloud.sample.json rename to core/config/voice/google-cloud.sample.json diff --git a/server/src/config/voice/watson-stt.sample.json b/core/config/voice/watson-stt.sample.json similarity index 100% rename from server/src/config/voice/watson-stt.sample.json rename to core/config/voice/watson-stt.sample.json diff --git a/server/src/config/voice/watson-tts.sample.json b/core/config/voice/watson-tts.sample.json similarity index 100% rename from server/src/config/voice/watson-tts.sample.json rename to core/config/voice/watson-tts.sample.json diff --git a/scripts/check.js b/scripts/check.js index adddcf3e..055f2afc 100644 --- a/scripts/check.js +++ b/scripts/check.js @@ -18,10 +18,10 @@ export default () => new Promise(async (resolve, reject) => { const pythonMinRequiredVersion = '3' const flitePath = 'bin/flite/flite' const coquiLanguageModelPath = 'bin/coqui/huge-vocabulary.scorer' - const amazonPath = 'server/src/config/voice/amazon.json' - const googleCloudPath = 'server/src/config/voice/google-cloud.json' - const watsonSttPath = 'server/src/config/voice/watson-stt.json' - const watsonTtsPath = 'server/src/config/voice/watson-tts.json' + const amazonPath = 'core/config/voice/amazon.json' + const googleCloudPath = 'core/config/voice/google-cloud.json' + const watsonSttPath = 'core/config/voice/watson-stt.json' + const watsonTtsPath = 'core/config/voice/watson-tts.json' const nlpModelPath = 'core/data/leon-model.nlp' const report = { can_run: { title: 'Run', type: 'error', v: true }, diff --git a/server/src/core/synchronizer.js b/server/src/core/synchronizer.js index 3dbb68cf..c418696e 100644 --- a/server/src/core/synchronizer.js +++ b/server/src/core/synchronizer.js @@ -1,5 +1,6 @@ import { google } from 'googleapis' import fs from 'fs' +import path from 'path' import { waterfall } from 'async' import log from '@/helpers/log' @@ -58,7 +59,7 @@ class Synchronizer { const driveFolderName = `leon-${this.classification.domain}-${this.classification.skill}` const folderMimeType = 'application/vnd.google-apps.folder' const entities = fs.readdirSync(this.downloadDir) - const key = JSON.parse(fs.readFileSync(`${__dirname}/../config/synchronizer/google-drive.json`, 'utf8')) + const key = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'core/config/synchronizer/google-drive.json'), 'utf8')) const authClient = new google.auth.JWT( key.client_email, key, diff --git a/server/src/stt/google-cloud-stt/parser.js b/server/src/stt/google-cloud-stt/parser.js index ae8fdd5b..9e1f1e39 100644 --- a/server/src/stt/google-cloud-stt/parser.js +++ b/server/src/stt/google-cloud-stt/parser.js @@ -1,3 +1,4 @@ +import path from 'path' import stt from '@google-cloud/speech' import log from '@/helpers/log' @@ -18,7 +19,7 @@ parser.conf = { * the env variable "GOOGLE_APPLICATION_CREDENTIALS" provides the JSON file path */ parser.init = () => { - process.env.GOOGLE_APPLICATION_CREDENTIALS = `${__dirname}/../../config/voice/google-cloud.json` + process.env.GOOGLE_APPLICATION_CREDENTIALS = path.join(process.cwd(), 'core/config/voice/google-cloud.json') try { client = new stt.SpeechClient() diff --git a/server/src/stt/stt.js b/server/src/stt/stt.js index f6ec80e3..95687944 100644 --- a/server/src/stt/stt.js +++ b/server/src/stt/stt.js @@ -1,4 +1,5 @@ import fs from 'fs' +import path from 'path' import Asr from '@/core/asr' import log from '@/helpers/log' @@ -32,9 +33,9 @@ class Stt { /* istanbul ignore next */ if (this.provider === 'google-cloud-stt' && typeof process.env.GOOGLE_APPLICATION_CREDENTIALS === 'undefined') { - process.env.GOOGLE_APPLICATION_CREDENTIALS = `${__dirname}/../config/voice/google-cloud.json` + process.env.GOOGLE_APPLICATION_CREDENTIALS = path.join(process.cwd(), 'core/config/voice/google-cloud.json') } else if (typeof process.env.GOOGLE_APPLICATION_CREDENTIALS !== 'undefined' - && process.env.GOOGLE_APPLICATION_CREDENTIALS.indexOf('config/voice/google-cloud.json') === -1) { + && process.env.GOOGLE_APPLICATION_CREDENTIALS.indexOf('google-cloud.json') === -1) { log.warning(`The "GOOGLE_APPLICATION_CREDENTIALS" env variable is already settled with the following value: "${process.env.GOOGLE_APPLICATION_CREDENTIALS}"`) } diff --git a/server/src/stt/watson-stt/parser.js b/server/src/stt/watson-stt/parser.js index 3d6b6cef..ead7dac5 100644 --- a/server/src/stt/watson-stt/parser.js +++ b/server/src/stt/watson-stt/parser.js @@ -1,6 +1,7 @@ import Stt from 'ibm-watson/speech-to-text/v1' import { IamAuthenticator } from 'ibm-watson/auth' import fs from 'fs' +import path from 'path' import { Duplex } from 'stream' import log from '@/helpers/log' @@ -19,7 +20,7 @@ parser.conf = { * Initialize Watson Speech-to-Text based on credentials in the JSON file */ parser.init = () => { - const config = JSON.parse(fs.readFileSync(`${__dirname}/../../config/voice/watson-stt.json`, 'utf8')) + const config = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'core/config/voice/watson-stt.json'), 'utf8')) try { client = new Stt({ diff --git a/server/src/tts/amazon-polly/synthesizer.js b/server/src/tts/amazon-polly/synthesizer.js index 58ab64ce..ec3510ad 100644 --- a/server/src/tts/amazon-polly/synthesizer.js +++ b/server/src/tts/amazon-polly/synthesizer.js @@ -3,6 +3,7 @@ import Ffmpeg from 'fluent-ffmpeg' import { path as ffmpegPath } from '@ffmpeg-installer/ffmpeg' import { path as ffprobePath } from '@ffprobe-installer/ffprobe' import fs from 'fs' +import path from 'path' import log from '@/helpers/log' import string from '@/helpers/string' @@ -29,7 +30,7 @@ synthesizer.conf = { * Initialize Amazon Polly based on credentials in the JSON file */ synthesizer.init = (lang) => { - const config = JSON.parse(fs.readFileSync(`${__dirname}/../../config/voice/amazon.json`, 'utf8')) + const config = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'core/config/voice/amazon.json'), 'utf8')) synthesizer.conf.VoiceId = voices[lang].VoiceId try { diff --git a/server/src/tts/google-cloud-tts/synthesizer.js b/server/src/tts/google-cloud-tts/synthesizer.js index 2a0bf8fb..285d0096 100644 --- a/server/src/tts/google-cloud-tts/synthesizer.js +++ b/server/src/tts/google-cloud-tts/synthesizer.js @@ -3,6 +3,7 @@ import Ffmpeg from 'fluent-ffmpeg' import { path as ffmpegPath } from '@ffmpeg-installer/ffmpeg' import { path as ffprobePath } from '@ffprobe-installer/ffprobe' import fs from 'fs' +import path from 'path' import log from '@/helpers/log' import string from '@/helpers/string' @@ -37,7 +38,7 @@ synthesizer.conf = { * The env variable "GOOGLE_APPLICATION_CREDENTIALS" provides the JSON file path */ synthesizer.init = (lang) => { - process.env.GOOGLE_APPLICATION_CREDENTIALS = `${__dirname}/../../config/voice/google-cloud.json` + process.env.GOOGLE_APPLICATION_CREDENTIALS = path.join(process.cwd(), 'core/config/voice/google-cloud.json') synthesizer.conf.voice = voices[lang] try { diff --git a/server/src/tts/tts.js b/server/src/tts/tts.js index d92df0d4..667e3858 100644 --- a/server/src/tts/tts.js +++ b/server/src/tts/tts.js @@ -1,5 +1,6 @@ import events from 'events' import fs from 'fs' +import path from 'path' import log from '@/helpers/log' import lang from '@/helpers/lang' @@ -39,9 +40,9 @@ class Tts { /* istanbul ignore next */ if (this.provider === 'google-cloud-tts' && typeof process.env.GOOGLE_APPLICATION_CREDENTIALS === 'undefined') { - process.env.GOOGLE_APPLICATION_CREDENTIALS = `${__dirname}/../config/voice/google-cloud.json` + process.env.GOOGLE_APPLICATION_CREDENTIALS = path.join(process.cwd(), 'core/config/voice/google-cloud.json') } else if (typeof process.env.GOOGLE_APPLICATION_CREDENTIALS !== 'undefined' - && process.env.GOOGLE_APPLICATION_CREDENTIALS.indexOf('config/voice/google-cloud.json') === -1) { + && process.env.GOOGLE_APPLICATION_CREDENTIALS.indexOf('google-cloud.json') === -1) { log.warning(`The "GOOGLE_APPLICATION_CREDENTIALS" env variable is already settled with the following value: "${process.env.GOOGLE_APPLICATION_CREDENTIALS}"`) } diff --git a/server/src/tts/watson-tts/synthesizer.js b/server/src/tts/watson-tts/synthesizer.js index 6aaa8e09..69cbb21b 100644 --- a/server/src/tts/watson-tts/synthesizer.js +++ b/server/src/tts/watson-tts/synthesizer.js @@ -4,6 +4,7 @@ import Ffmpeg from 'fluent-ffmpeg' import { path as ffmpegPath } from '@ffmpeg-installer/ffmpeg' import { path as ffprobePath } from '@ffprobe-installer/ffprobe' import fs from 'fs' +import path from 'path' import log from '@/helpers/log' import string from '@/helpers/string' @@ -30,7 +31,7 @@ synthesizer.conf = { * Initialize Watson Text-to-Speech based on credentials in the JSON file */ synthesizer.init = (lang) => { - const config = JSON.parse(fs.readFileSync(`${__dirname}/../../config/voice/watson-tts.json`, 'utf8')) + const config = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'core/config/voice/watson-tts.json'), 'utf8')) synthesizer.conf.voice = voices[lang].voice try {