2021-03-04 17:49:52 +03:00
|
|
|
import { command } from 'execa'
|
2019-02-10 15:26:50 +03:00
|
|
|
import fs from 'fs'
|
|
|
|
|
|
|
|
import log from '@/helpers/log'
|
|
|
|
import os from '@/helpers/os'
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup offline text-to-speech
|
|
|
|
*/
|
|
|
|
export default () => new Promise(async (resolve, reject) => {
|
|
|
|
log.info('Setting up offline text-to-speech...')
|
|
|
|
|
|
|
|
const destFliteFolder = 'bin/flite'
|
|
|
|
const tmpDir = 'scripts/tmp'
|
|
|
|
let makeCores = ''
|
|
|
|
if (os.cpus().length > 2) {
|
|
|
|
makeCores = `-j ${os.cpus().length - 2}`
|
|
|
|
}
|
|
|
|
let downloader = 'wget'
|
|
|
|
if (os.get().type === 'macos') {
|
|
|
|
downloader = 'curl -L -O'
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!fs.existsSync(`${destFliteFolder}/flite`)) {
|
|
|
|
try {
|
|
|
|
log.info('Downloading run-time synthesis engine...')
|
2021-03-04 17:49:52 +03:00
|
|
|
await command(`cd ${tmpDir} && ${downloader} http://www.festvox.org/flite/packed/flite-2.1/flite-2.1-release.tar.bz2`, { shell: true })
|
2019-02-10 15:26:50 +03:00
|
|
|
log.success('Run-time synthesis engine download done')
|
|
|
|
log.info('Unpacking...')
|
2021-03-04 17:49:52 +03:00
|
|
|
await command(`cd ${tmpDir} && tar xfvj flite-2.1-release.tar.bz2 && cp ../assets/leon.lv flite-2.1-release/config`, { shell: true })
|
2019-02-10 15:26:50 +03:00
|
|
|
log.success('Unpack done')
|
|
|
|
log.info('Configuring...')
|
2021-03-04 17:49:52 +03:00
|
|
|
await command(`cd ${tmpDir}/flite-2.1-release && ./configure --with-langvox=leon`, { shell: true })
|
2019-02-10 15:26:50 +03:00
|
|
|
log.success('Configure done')
|
|
|
|
log.info('Building...')
|
2021-03-04 17:49:52 +03:00
|
|
|
await command(`cd ${tmpDir}/flite-2.1-release && make ${makeCores}`, { shell: true })
|
2019-02-10 15:26:50 +03:00
|
|
|
log.success('Build done')
|
|
|
|
log.info('Cleaning...')
|
2021-03-04 17:49:52 +03:00
|
|
|
await command(`cp -f ${tmpDir}/flite-2.1-release/bin/flite ${destFliteFolder} && rm -rf ${tmpDir}/flite-2.1-release*`, { shell: true })
|
2019-02-10 15:26:50 +03:00
|
|
|
log.success('Clean done')
|
|
|
|
log.success('Offline text-to-speech installed')
|
|
|
|
|
|
|
|
resolve()
|
|
|
|
} catch (e) {
|
|
|
|
log.error(`Failed to install offline text-to-speech: ${e}`)
|
|
|
|
reject(e)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
log.success('Offline text-to-speech is already installed')
|
|
|
|
resolve()
|
|
|
|
}
|
|
|
|
})
|