Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save invincible/bc0a2d61d43f66ce6059210968fc4c9e to your computer and use it in GitHub Desktop.
Save invincible/bc0a2d61d43f66ce6059210968fc4c9e to your computer and use it in GitHub Desktop.
Yandex Cloud SpeechKit (TTS) Example on Node.js - Пример работы с API технологии синтеза речи Yandex Cloud SpeechKit
const fetch = require('node-fetch');
const api_key = 'API_KEY';
const { URLSearchParams } = require('url');
const fs = require('fs');
const params = new URLSearchParams();
const text = 'Добрый день, у нас новая акция! Пицца Добряк сегодня за полцены, закажите по телефону 222. Уже ждем вашего заказа :) '
params.append('text', text);
params.append('voice', 'zahar');
params.append('emotion', 'good');
params.append('lang', 'ru-RU');
params.append('speed', '1.0');
params.append('format', 'oggopus');
fetch('https://tts.api.cloud.yandex.net/speech/v1/tts:synthesize', {
method: 'post',
body: params,
headers: {
// 'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Api-Key ' + api_key,
},
})
.then(res => {
console.log(res);
// return res.json();
const dest = fs.createWriteStream('./octocat.ogg');
res.body.pipe(dest);
})
.catch(err => console.error(err));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment