npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

moises

v3.1.0

Published

This package bundles an `SDK` and a `CLI` to allow basic usage of the [Moises Developer Platform](https://developer.moises.ai).

Downloads

1,641

Readme

Moises Developer Platform - Node.js SDK

This package bundles an SDK and a CLI to allow basic usage of the Moises Developer Platform.

Quick start

Here's how you can easily process a folder containing audio files against the moises/stems-vocals-drums-bass-other workflow:

import Moises from "moises/sdk"

const moises = new Moises({ apiKey: "your-api-key" })

await moises.processFolder(
  "moises/stems-vocals-drums-bass-other",
  "./audio",
  "./stems",
  {}
)

Installation

npm i moises --save

API Reference

Types

interface Job {
  id: string
  app: string
  workflow: string
  name: string
  status: "QUEUED" | "STARTED" | "SUCCEEDED" | "FAILED"
  workflowParams: {
    inputUrl: string
    [key: string]: string
  }
  result: {
    [key: string]: string
  }
  createdAt: string
  startedAt: string
  completedAt: string | null
}

Upload file

Uploads a local file to our temporary file server. Returns an temporary download url you can use on other methods.

uploadFile(fileLocation: string): Promise<string>
Example
const downloadUrl = await moises.uploadFile(fileLocation)

Add a job

Creates a new job and returns its corresponding JobId. The jobName can be anything you want (useful for your own reference).

addJob(jobName: string, workflowName: string, {
  inputUrl: string
  [key: string]: string
}): Promise<string>
Example
const downloadUrl = await moises.uploadFile("./song.mp3")
const jobId = await moises.addJob(
  "job-1",
  "moises/stems-vocals-drums-bass-other",
  { inputUrl: downloadUrl }
)

Check the documentation for all the existing workflows and expected correspondent parameters.

Get a job

Gets a job information by its id.

getJob(id: string): Promise<Job>
Example
const job = await moises.getJob(/* jobId */)

The job variable value:

{
  "id": "2e35babc-91c4-4121-89f4-5a2acf956b28",
  "name": "My job 123",
  "status": "SUCCEEDED",
  "workflow": {
    "id": "2ae5eea3-63dd-445e-9a3f-ff0473e82fd2",
    "name": "Stems Isolations - Vocals & accompaniments"
  },
  "workflowParams": {
    "inputUrl": "https://your-server.com/audio-input.m4a"
  },
  "result": {
    "vocals": "https://cdn.moises.ai/something/vocals.wav",
    "accompaniments": "https://cdn.moises.ai/something/accompaniments.wav"
  },
  "createdAt": "2022-12-07T19:21:42.170Z",
  "startedAt": "2022-12-07T19:21:42.307Z",
  "completedAt": "2022-12-07T19:22:00.325Z"
}

List jobs

Return all existing jobs associated with the provided apiKey. You can optionally filter by status and workflow:

listJobs(filters?: { status?: Status[]; workflow?: string[] }): Promise<Job[]>
Example
const jobs = await moises.listJobs()
const jobs = await moises.listJobs({
  status: ["FAILED"],
  workflow: ["workflow-a", "workflow-b"],
})

Delete a job

Delete a job by its id.

deleteJob(id: string): Promise<void>

Wait for a job completion

Waits until the job status is either SUCCEEDED or FAILED, and returns its information.

waitForJobCompletion(id: string): Promise<Job>
Example
const job = await moises.waitForJobCompletion(/* jobId */)

if (job.status === "SUCCEEDED") {
  console.log("Job succeeded!")
} else {
  console.log("Job failed!")
}

Download all job results

Download all the job results to a local folder.

downloadJobResults(jobIdOrJobData: string | Job, outputFolder: string): Promise<string[]>

This function also creates a file called workflow.result.json containing the result in the JSON format. When an output is a file, that field will contain the relative path to the file.

Example
const resultPaths = await moises.downloadJobResults(/* jobId */, "./stems")

Or, if you already have the job object...

const job = await moises.waitForJobCompletion(/* jobId */)
const resultPaths = await moises.downloadJobResults(job, "./stems")

If the workflows has two outputs, vocals in WAVE format and bpm, two files will be created at the given folder: vocals.wav and workflow.result.json.

// workflow.result.json
{
  "vocals": "./vocals.wav",
  "bpm": "64"
}

Process a single file

Adds a new job and monitor its status till completion. At the end, the job is deleted.

processFile(workflow: string, origin: string, outputFolder: string): Promise<void>
Example
await moises.processFile(
  "moises/stems-vocals-drums-bass-other",
  "./song.mp3",
  "./stems"
)

Process a folder

Adds a new job for each file in the folder and monitor their status till completion. At the end, the jobs are deleted.

processFolder(
  workflow: string,
  inputFolder: string,
  outputFolder: string,
  options: { concurrency?: number }
): Promise<"Ended normally" | "Aborted">
Example
await moises.processFolder(
  "moises/stems-vocals-drums-bass-other",
  "./songs",
  "./stems",
  {}
)

Complete example

import Moises from "moises/sdk"

const moises = new Moises({ apiKey: "your-api-key" })

const downloadUrl = await moises.uploadFile("./song.mp3")
const jobId = await moises.addJob(
  "job-1",
  "moises/stems-vocals-drums-bass-other",
  { inputUrl: downloadUrl }
)
const job = await moises.waitForJobCompletion(jobId)

if (job.status === "SUCCEEDED") {
  const files = await moises.downloadJobResults(job, "./stems")
  console.log("Result:", files)
} else {
  console.log("Job failed!")
}

await moises.deleteJob(jobId)

CLI

More information on the CLI Documentation page.