End-to-end Example with NodeJS

❗️

Tip

If you are running this package in a CommonJS app, or if you have not set a compiler to convert your code ES 2015 code into that; use the approach below.
To read more about different javascript modules format: https://code-trotter.com/web/understand-the-different-javascript-modules-formats/

import apiaudio, { Script, Voice, Speech, Sound, Mastering }  from "apiaudio"

async function example() {
  try {
    apiaudio.configure({ apiKey: "<<apiKey>>" });
    
    let script = await Script.create({ scriptText: "Hello world" });
    console.log(script);

    script = await Script.retrieve(script["scriptId"]);
    console.log(script);

    let scripts = await Script.list();
    console.log(scripts);

    let voices = await Voice.list();
    console.log(voices);

    let speech = await Speech.create({ scriptId: script["scriptId"] });
    console.log(speech);

    let speechResult = await Speech.retrieve(script["scriptId"]);
    console.log(speechResult);
    
    let bg_tracks = await Sound.list();
    console.log(bg_tracks);
    
    let mastering = await Mastering.create({ scriptId: script["scriptId"], backgroundTrackId: bg_tracks[0]["id"] });
    console.log(mastering);
    
    let masteringResult = await Mastering.retrieve(script["scriptId"], {});
    console.log(masteringResult);
    
  } catch (e) {
    console.error(e);
  }
}

example();

Here is another end-to-end example in CommonJS.

const apiaudio = require("apiaudio").default;

async function example() {
  try {
    apiaudio.configure({ apiKey: "<<apiKey>>" });
    let script = await apiaudio.Script.create({ scriptText: "Hello world" });
    console.log(script);

    script = await apiaudio.Script.retrieve(script["scriptId"]);
    console.log(script);

    let scripts = await apiaudio.Script.list();
    console.log(scripts);
    
    let voices = await apiaudio.Voice.list();
    console.log(voices);

    let speech = await apiaudio.Speech.create({ scriptId: script["scriptId"] });
    console.log(speech);

    let speechResult = await apiaudio.Speech.retrieve(script["scriptId"]);
    console.log(speechResult);
    
    let bg_tracks = await apiaudio.Sound.list();
    console.log(bg_tracks);
    
    let mastering = await apiaudio.Mastering.create({ scriptId: script["scriptId"], backgroundTrackId: bg_tracks[0]["id"] });
    console.log(mastering);
    
    let masteringResult = await apiaudio.Mastering.retrieve(script["scriptId"], {});
    console.log(masteringResult);
    
  } catch (e) {
    console.error(e);
  }
}

example();