Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

202
Views
Writing a Text to Speech file as an MP3 - IBM Watson

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?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

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.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!