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,626
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.