1
1
mirror of https://github.com/leon-ai/leon.git synced 2024-12-24 17:23:23 +03:00
leon/scripts/setup-offline/setup-stt.js

58 lines
1.9 KiB
JavaScript
Raw Normal View History

import fs from 'node:fs'
2019-02-10 15:26:50 +03:00
import { command } from 'execa'
import { LogHelper } from '@/helpers/log-helper'
import { OSHelper } from '@/helpers/os-helper'
2019-02-10 15:26:50 +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) => {
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'
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 {
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 }
)
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 }
)
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) {
LogHelper.error(`Failed to install offline speech-to-text: ${e}`)
2022-09-03 14:12:41 +03:00
reject(e)
}
} else {
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
})