1

I'm following the documentation for the Node.JS implementation of the IBM Watson Text-to-Speech API.

I want to output the resultant file into MP3 format. The documentation recommends augmenting the base code but I'm not sure how to do that. My code is rendering unplayable MP3s.

Here is what it says in the documentation:

textToSpeech.synthesize(synthesizeParams)
  .then(response => {

    // The following line is necessary only for
    // wav formats; otherwise, `response.result`
    // can be directly piped to a file.

    return textToSpeech.repairWavHeaderStream(response.result);
  })
  .then(buffer => {
    fs.writeFileSync('hello_world.wav', buffer);
  })
  .catch(err => {
    console.log('error:', err);
  });

As it says, response.result should be directly piped to a file. This is one of my many attempts (that renders an error).

textToSpeech
  .synthesize(synthesizeParams)  
  .then(response => {
    fs.writeFileSync('Hello.mp3', response.result)
  })
  .catch(err => {
    console.log('error:', err)
  })

How can I output the text-to-speech input as an MP3?

WΔ_
  • 1,229
  • 4
  • 20
  • 34

1 Answers1

0

Provided your params are requesting an mp3 file, this will be the accept parameter, then your code looks ok. So if the output file isn't being recognised as an audio, then it is most likely a text file containing an error message. This error message will indicate what is wrong, which most likely will be an unauthorised message.

I take it that your catch error block isn't logging anything.

chughts
  • 4,210
  • 2
  • 14
  • 27