How to use the ibm-watson/text-to-speech/v1.URL function in ibm-watson

To help you get started, we’ve selected a few ibm-watson examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github watson-developer-cloud / speech-javascript-sdk / examples / server.js View on Github external
const token = response.token || response;
    if (process.env.SPEECH_TO_TEXT_IAM_APIKEY) {
      res.json({ accessToken: token, url: sttCredentials.url });
    } else {
      res.json({ token: token, url: sttCredentials.url });
    }
  });
});

// text to speech token endpoint
const ttsCredentials = Object.assign(
  {
    username: process.env.TEXT_TO_SPEECH_USERNAME, // or hard-code credentials here
    password: process.env.TEXT_TO_SPEECH_PASSWORD,
    iam_apikey: process.env.TEXT_TO_SPEECH_IAM_APIKEY, // if using an RC service
    url: process.env.TEXT_TO_SPEECH_URL ? process.env.TEXT_TO_SPEECH_URL : TextToSpeechV1.URL
  },
  vcapServices.getCredentials('text_to_speech') // pulls credentials from environment in bluemix, otherwise returns {}
);
app.use('/api/text-to-speech/token', function(req, res) {
  const ttsAuthService = new AuthorizationV1(ttsCredentials);
  ttsAuthService.getToken(function(err, response) {
    if (err) {
      console.log('Error retrieving token: ', err);
      res.status(500).send('Error retrieving token');
      return;
    }
    const token = response.token || response;
    if (process.env.TEXT_TO_SPEECH_IAM_APIKEY) {
      res.json({ accessToken: token, url: ttsCredentials.url });
    } else {
      res.json({ token: token, url: ttsCredentials.url });