Skip to content

Commit

Permalink
feat: select language, punctuation
Browse files Browse the repository at this point in the history
  • Loading branch information
popstas committed Feb 7, 2023
1 parent 1959798 commit cca04cb
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ async function fileToRecognize(filePath, filename = '') {

// send to STT
console.log(colors.yellow('3/4 Send to SpeechKit...'));
const opId = await sendAudio(recognitionUri);
const opId = await sendAudio({audioUri: recognitionUri, language, punctuation});
if (opId.error) {
return { error: opId.error };
}
console.log('Uploaded, id: ' + opId);

if (!fs.existsSync(opsPath)) fs.mkdirSync(opsPath, { recursive: true }); // create dir
Expand Down Expand Up @@ -216,12 +219,18 @@ async function uploadToYandexStorage(filePath) {
}
}

async function sendAudio(audioUri) {
const encoding = {
async function sendAudio({audioUri, language, punctuation = true}) {
const langMap = {
'ru': 'ru-RU',
'en': 'en-US',
}
const languageCode = langMap[language] || 'ru-RU';
const audioEncoding = {
ogg: 'OGG_OPUS',
pcm: 'LINEAR16_PCM'
}[audioType];

const model = language === 'ru' ? config.specificationModel : 'general';
const data = {
config: {
specification: {
Expand All @@ -246,7 +255,9 @@ async function sendAudio(audioUri) {
return res.data.id;
} catch (e) {
console.log('e.response.data.message: ', e.response.data.message);
console.log('error: ', e);
return { error: e.response.data.message };

// console.log('error: ', e);
}
}

Expand Down

0 comments on commit cca04cb

Please # to comment.