This package bundles an `SDK` and a `CLI` to allow basic usage of the [Moises Developer Platform](https://developer.moises.ai).
npm install moisesThis 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:
``ts
import Moises from "moises/sdk"
const moises = new Moises({ apiKey: "your-api-key" })
await moises.processFolder(
"moises/stems-vocals-drums-bass-other",
"./audio",
"./stems",
{}
)
`
`shell`
npm i moises --save
#### Types
`ts`
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.
`ts`
uploadFile(fileLocation: string): Promise
##### Example
`ts`
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).
`ts`
addJob(jobName: string, workflowName: string, {
inputUrl: string
[key: string]: string
}): Promise
##### Example
`ts`
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.
`ts`
getJob(id: string): Promise
##### Example
`ts`
const job = await moises.getJob(/ jobId /)
The job variable value:
`json`
{
"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:
`ts`
listJobs(filters?: { status?: Status[]; workflow?: string[] }): Promise
##### Example
`ts`
const jobs = await moises.listJobs()
`ts`
const jobs = await moises.listJobs({
status: ["FAILED"],
workflow: ["workflow-a", "workflow-b"],
})
#### Delete a job
Delete a job by its id.
`ts`
deleteJob(id: string): Promise
#### Wait for a job completion
Waits until the job status is either SUCCEEDED or FAILED, and returns its information.
`ts`
waitForJobCompletion(id: string): Promise
##### Example
`ts
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.
`ts`
downloadJobResults(jobIdOrJobData: string | Job, outputFolder: string): Promise
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
`ts`
const resultPaths = await moises.downloadJobResults(/ jobId /, "./stems")
Or, if you already have the job object...
`ts`
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.
`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.
`ts`
processFile(workflow: string, origin: string, outputFolder: string): Promise
##### Example
`ts`
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.
`ts`
processFolder(
workflow: string,
inputFolder: string,
outputFolder: string,
options: { concurrency?: number }
): Promise<"Ended normally" | "Aborted">
##### Example
`ts`
await moises.processFolder(
"moises/stems-vocals-drums-bass-other",
"./songs",
"./stems",
{}
)
`ts
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)
``
More information on the CLI Documentation page.