2019-02-10 15:26:50 +03:00
|
|
|
import { shell } from 'execa'
|
|
|
|
import fs from 'fs'
|
|
|
|
|
|
|
|
import log from '@/helpers/log'
|
|
|
|
import os from '@/helpers/os'
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup offline speech-to-text
|
|
|
|
*/
|
|
|
|
export default () => new Promise(async (resolve, reject) => {
|
|
|
|
log.info('Setting up offline speech-to-text...')
|
|
|
|
|
|
|
|
const destDeepSpeechFolder = 'bin/deepspeech'
|
|
|
|
const tmpDir = 'scripts/tmp'
|
2019-06-18 21:53:20 +03:00
|
|
|
const deepSpeechVersion = '0.5.0'
|
|
|
|
const archiveName = `deepspeech-${deepSpeechVersion}-models.tar.gz`
|
2019-02-10 15:26:50 +03:00
|
|
|
let downloader = 'wget'
|
|
|
|
if (os.get().type === 'macos') {
|
|
|
|
downloader = 'curl -L -O'
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!fs.existsSync(`${destDeepSpeechFolder}/lm.binary`)) {
|
|
|
|
try {
|
|
|
|
log.info('Downloading pre-trained model...')
|
2019-06-18 21:53:20 +03:00
|
|
|
await shell(`cd ${tmpDir} && ${downloader} https://github.com/mozilla/DeepSpeech/releases/download/v${deepSpeechVersion}/${archiveName}`)
|
2019-02-10 15:26:50 +03:00
|
|
|
log.success('Pre-trained model download done')
|
|
|
|
log.info('Unpacking...')
|
|
|
|
await shell(`cd ${tmpDir} && tar xvfz ${archiveName}`)
|
|
|
|
log.success('Unpack done')
|
|
|
|
log.info('Moving...')
|
2019-06-18 21:53:20 +03:00
|
|
|
await shell(`mv -f ${tmpDir}/deepspeech-${deepSpeechVersion}-models/* ${destDeepSpeechFolder} && rm -rf ${tmpDir}/${archiveName} ${tmpDir}/models`)
|
2019-02-10 15:26:50 +03:00
|
|
|
log.success('Move done')
|
|
|
|
log.success('Offline speech-to-text installed')
|
|
|
|
|
|
|
|
resolve()
|
|
|
|
} catch (e) {
|
|
|
|
log.error(`Failed to install offline speech-to-text: ${e}`)
|
|
|
|
reject(e)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
log.success('Offline speech-to-text is already installed')
|
|
|
|
resolve()
|
|
|
|
}
|
|
|
|
})
|