IBM Watson Speech-to-text API can't figure it out

Hi!

I’m trying to complete a coding challenge where we are asked to build a basic web app that uses the IBM Watson Speech To Text API. I’m still beginner but have worked with openweather and google books apis before, but this time it feels I dont know what is what…

Anyone had any experience with this API that may be able to help me get the logic part done?

I got as far as getting an IBM Id and API Key as well.

App would be either plain old html+js or might go the React way also, no preference.

Working example.
This won’t work in a browser because the enpoint have CORS.
Put this code into .js file and run with node.
audio-file.flac must be in the same directory.
Don’t forget to install node-fetch.

const fetch = require('node-fetch');
const fs = require('fs');

const url = 'https://stream-fra.watsonplatform.net/speech-to-text/api';
const apiKey = 'YOUR_API_KEY';

const file = fs.readFileSync('./audio-file.flac');

const apiKeyEnc = Buffer.from(`apiKey:${apiKey}`).toString('base64');

fetch(`${url}/v1/recognize`, {
  body: file,
  method: 'post',
  headers: {
    authorization: `Basic ${apiKeyEnc}`,
    'Content-Type': 'audio/flac',
  },
})
  .then(res => res.json())
  .then(({ results }) => {
    results.forEach(res => {
      res.alternatives.forEach(r => console.log(r.transcript));
    });
  })
  .catch(e => console.log(e));

Hmmm nope. I cant make sense of all that. I might need to come back to this challenge once I am a bit more experienced. Thanks for the info, though!

Ok, here’s browser version: https://codepen.io/jenovs/pen/zbzRzr?editors=1011
Does this make sense?

(Don’t forget to input your api key).