2022-09-26 18:28:25 +03:00
|
|
|
import fs from 'node:fs'
|
2019-02-10 15:26:50 +03:00
|
|
|
|
2022-09-26 19:01:03 +03:00
|
|
|
import { command } from 'execa'
|
|
|
|
|
2022-09-26 16:29:56 +03:00
|
|
|
import { LogHelper } from '@/helpers/log-helper'
|
2022-09-26 16:32:59 +03:00
|
|
|
import { OSHelper } from '@/helpers/os-helper'
|
2019-02-10 15:26:50 +03:00
|
|
|
|
|
|
|
/**
|
2022-11-13 19:49:24 +03:00
|
|
|
* Set up offline speech-to-text
|
2019-02-10 15:26:50 +03:00
|
|
|
*/
|
2022-09-03 14:12:41 +03:00
|
|
|
export default () =>
|
|
|
|
new Promise(async (resolve, reject) => {
|
2022-09-26 16:29:56 +03:00
|
|
|
LogHelper.info('Setting up offline speech-to-text...')
|
2019-02-10 15:26:50 +03:00
|
|
|
|
2022-09-03 14:12:41 +03:00
|
|
|
const destCoquiFolder = 'bin/coqui'
|
|
|
|
const tmpDir = 'scripts/tmp'
|
|
|
|
// check this repo for updates: https://github.com/coqui-ai/STT-models/tree/main/english/coqui
|
|
|
|
const coquiModelVersion = '1.0.0'
|
|
|
|
let downloader = 'wget'
|
2022-09-26 16:32:59 +03:00
|
|
|
if (OSHelper.getInformation().type === 'macos') {
|
2022-09-03 14:12:41 +03:00
|
|
|
downloader = 'curl -L -O'
|
|
|
|
}
|
2019-02-10 15:26:50 +03:00
|
|
|
|
2022-09-03 14:12:41 +03:00
|
|
|
if (!fs.existsSync(`${destCoquiFolder}/model.tflite`)) {
|
|
|
|
try {
|
2022-09-26 16:29:56 +03:00
|
|
|
LogHelper.info('Downloading pre-trained model...')
|
2022-09-03 14:12:41 +03:00
|
|
|
await command(
|
|
|
|
`cd ${tmpDir} && ${downloader} https://github.com/coqui-ai/STT-models/releases/download/english/coqui/v${coquiModelVersion}-huge-vocab/model.tflite`,
|
|
|
|
{ shell: true }
|
|
|
|
)
|
|
|
|
await command(
|
|
|
|
`cd ${tmpDir} && ${downloader} https://github.com/coqui-ai/STT-models/releases/download/english/coqui/v${coquiModelVersion}-huge-vocab/huge-vocabulary.scorer`,
|
|
|
|
{ shell: true }
|
|
|
|
)
|
2022-09-26 16:29:56 +03:00
|
|
|
LogHelper.success('Pre-trained model download done')
|
|
|
|
LogHelper.info('Moving...')
|
2022-09-03 14:12:41 +03:00
|
|
|
await command(
|
|
|
|
`mv -f ${tmpDir}/model.tflite ${destCoquiFolder}/model.tflite`,
|
|
|
|
{ shell: true }
|
|
|
|
)
|
|
|
|
await command(
|
|
|
|
`mv -f ${tmpDir}/huge-vocabulary.scorer ${destCoquiFolder}/huge-vocabulary.scorer`,
|
|
|
|
{ shell: true }
|
|
|
|
)
|
2022-09-26 16:29:56 +03:00
|
|
|
LogHelper.success('Move done')
|
|
|
|
LogHelper.success('Offline speech-to-text installed')
|
2019-02-10 15:26:50 +03:00
|
|
|
|
2022-09-03 14:12:41 +03:00
|
|
|
resolve()
|
|
|
|
} catch (e) {
|
2022-09-26 16:29:56 +03:00
|
|
|
LogHelper.error(`Failed to install offline speech-to-text: ${e}`)
|
2022-09-03 14:12:41 +03:00
|
|
|
reject(e)
|
|
|
|
}
|
|
|
|
} else {
|
2022-09-26 16:29:56 +03:00
|
|
|
LogHelper.success('Offline speech-to-text is already installed')
|
2019-02-10 15:26:50 +03:00
|
|
|
resolve()
|
|
|
|
}
|
2022-09-03 14:12:41 +03:00
|
|
|
})
|