UNPKG

umbot

Version:

Universal bot(vk, telegram, viber) or skills for Yandex.Alisa, Маруся and sber

86 lines (85 loc) 2.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.YandexSpeechKit = void 0; const YandexRequest_1 = require("./YandexRequest"); const mmApp_1 = require("../mmApp"); class YandexSpeechKit extends YandexRequest_1.YandexRequest { static TTS_API_URL = 'https://tts.api.cloud.yandex.net/speech/v1/tts:synthesize'; static E_GOOD = 'good'; static E_EVIL = 'evil'; static E_NEUTRAL = 'neutral'; static V_OKSANA = 'oksana'; static V_JANE = 'jane'; static V_OMAZH = 'omazh'; static V_ZAHAR = 'zahar'; static V_ERMIL = 'ermil'; static V_SILAERKAN = 'silaerkan'; static V_ERKANYAVAS = 'erkanyavas'; static V_ALYSS = 'alyss'; static V_NICK = 'nick'; static V_ALENA = 'alena'; static V_FILIPP = 'filipp'; static L_RU = 'ru-RU'; static L_EN = 'en_EN'; static L_TR = 'tr-TR'; static F_LPCM = 'lpcm'; static F_OGGOPUS = 'oggopus'; text; lang; voice; emotion; speed; format; sampleRateHertz; folderId; constructor(oauth = null) { super(oauth); this.lang = YandexSpeechKit.L_RU; this.emotion = YandexSpeechKit.E_NEUTRAL; this.speed = 1.0; this.format = YandexSpeechKit.F_OGGOPUS; this.folderId = null; this.voice = 'oksana'; if (oauth === null) { this.setOAuth(mmApp_1.mmApp.params.yandex_speech_kit_token || null); } } _initPost() { this._request.post = { text: this.text, lang: this.lang, voice: this.voice, format: this.format, }; if ([ YandexSpeechKit.V_SILAERKAN, YandexSpeechKit.V_ERKANYAVAS, YandexSpeechKit.V_ALYSS, YandexSpeechKit.V_NICK, ].indexOf(this.voice) === -1) { this._request.post.emotion = this.emotion; } if (this.voice !== YandexSpeechKit.V_ALENA && this.voice !== YandexSpeechKit.V_FILIPP) { if (this.speed < 0.1 || this.speed > 3.0) { this.speed = 1.0; } this._request.post.speed = this.speed; } if (this.format === YandexSpeechKit.F_LPCM && this.sampleRateHertz) { this._request.post.sampleRateHertz = this.sampleRateHertz; } if (this.folderId) { this._request.post.folderId = this.folderId; } } getTts(text = null) { if (text) { this.text = text; } this._request.url = YandexSpeechKit.TTS_API_URL; this._request.isConvertJson = false; this._initPost(); return this.call(); } } exports.YandexSpeechKit = YandexSpeechKit;