Exemple #1
0
							translator.translate(params, function(e, translatedText) {
								if (!e) {
									bot.say(to, translatedText + ' (' + inputLanguage + ' to ' + outputLanguage + ')');

									// stream spoken mp3 to uguu.se and provide link
									translator.speak(params, function(e, audiostream) {
										if (!e) {
											var req = request.post('https://uguu.se/api.php?d=upload-tool', function (err, resp, body) {
											  if (err) {
											    console.log('TRANSLATOR -- ' + err);
											    bot.say(to, 'There was an error with your translation.');
											  } else {
											    bot.say(to, 'Listen: ' + body);
											  }
											});
											var form = req.form();
											form.append('file', audiostream, {
											  filename: inputText + '_' + inputLanguage + '_to_' + outputLanguage + '.mp3',
											  contentType: params.format
											});
										} else {
											console.log('TRANSLATOR -- ' + e);
										}
									});

								} else {
									console.log('TRANSLATOR -- ' + e);
									bot.say(to, 'There was an error with your translation.');
								}
							});
Exemple #2
0
  return new Promise((resolve, reject) => {
    translator.speak(params, (error, audiostream) => {
      if (!error) {
        const uguu = 'https://uguu.se/api.php?d=upload-tool';
        const req = request.post(uguu, (e, response, body) => {
          if (e) {
            console.warn(`TRANSLATOR auto uguu request -- ${e}`);
            console.warn(e);
            reject('There was an error with your translation.');
          } else {
            resolve(body);
          }
        });

        const form = req.form();
        const filename = `${inputText}_${inputLanguage}_to_${outputLanguage}.mp3`;
        form.append('file', audiostream, {
          filename,
          contentType: params.format,
        });
      } else {
        reject(error);
      }
    });
  });