Git Product home page Git Product logo

music-generation-api-server's Introduction

Guide to use


Setup

  • Install Python 3 and Pip
  • Install the dependencies
   pip install tensorflow
   pip install Keras
   pip install numpy
   pip install pretty_midi
   pip install pickle5
   pip install Flask
   In order to be able to generate sheet music
   1. pip install music21 
   2. pip install matplotlib
   3. Install Musescore https://musescore.org/en/download
   4. Open sheet_music_generation/music21_musescore_work_together_configurer.py in text editor
   5. Change the path to the installed location of Musescore
   6. run: python sheet_music_generation/music21_musescore_work_together_configurer.py

You are all set !! 

Running the server

From the directory containing app.py in terminal, run: python app.py
Now the server should start and accept the requests at port 5000
In your case: localhost:5000


APIs available

GET:   /api/v1/information/keyNames
GET:   /api/v1/information/instruments
GET:   /api/v1/information/genre
GET:   /api/v1/information/all
POST:  /api/v1/generate
POST:  /api/v1/modify
GET:   /api/v1/sheet_music/<name>
GET:   /api/v1/music_mp3

APIs details


To retrieve all the information relevant to generating the music

respone comes in application/json form

GET:   /api/v1/information/all

eg:
localhost:5000/api/v1/information/all

returns

{
    "genre": [
        {
            "id": 0,
            "name": "Blues"
        },
        {
            "id": 1,
            "name": "Classical"
        },
       ...
    ],
    "instruments": [
        {
            "id": 0,
            "name": "Electric Guitar (jazz)"
        },
        {
            "id": 1,
            "name": "Acoustic Grand Piano"
        },
        ...
    ],
    "keys": [
        "C",
        "C#",
        ...
    ]
}

To retrieve selected information

GET:   /api/v1/information/keyNames
GET:   /api/v1/information/instruments
GET:   /api/v1/information/genre

eg:
  localhost:5000/api/v1/information/genre
  
  gives:

  [
      {
          "id": 0,
          "name": "Blues"
      },
      {
          "id": 1,
          "name": "Classical"
      },
      ...
  ]

To generate music

POST: /api/v1/generate
It requires:
Request Header: Content-Type: application/json
Request Body in application/json form
Response: music in midi format

example request body:

{
  "genre_id": 2,
  "instrument_id": 3,
  "num_bars": 64,
  "BPM": 100,
  "chord_temperature": 1,
  "seed_length": 4,
  
  "note_cap": 2,

  "key": "C",
  "octave_type": "lower",
  "which_octave": 2
}

genre_id
id of the genre of the music to be produced

instrument_id
id of the instrument type to generate the music for

num_bars
how many bars of music to generate (length of the music)

BPM
speed of the generated music (beats per minute)

chord_temperature

degree of randomness in the generated music
should be in the range [0.1 to 2]

seed_length

number of bars to seed with while generating the music 
(how much of actual music to feed to generate new music)

note_cap

number of notes that can be played together at the same time
it may not be exact because chord progression is not bound by it
but it effects the melody produced
its value should be in the range [1 to 5]
I suggest the front-end to have a slider rather than exact number as a input

If the produced music has too many notes at a same time
you can decrease this value
This attribute is optional
if not provided it takes the default value of 4

key
key of the generated music (eg. F#, G, A, ..)

octave_type

can take values: "higher" or "lower"
it modifies the music to be in higher or lower octave
higher octave means of high pitch and lower means of lower pitch

which_octave

this number specifies how many octaves higher or lower to go
if key is D#, octave_type is "higher" and which_octave is 2
then the music will shift towards higher frequency, 2 octave higher in the D# key 
if octave_type == "lower" then which_octave can be in the range [0 to 2]
if octave_type == "higher" then which_octave can be in the range [0 to 3]
Compulsory Parameters
"num_bars"
"BPM"
"chord_temperature"
"seed_length"
Optional Parameters
following parameters can come independently
"genre_id"
"instrument_id"
"note_cap"

following paramaters must come together
"key"
"octave_type"
"which_octave"

To modify the generated music

POST: /api/v1/modify

Features
  • ability to change the key of the music
  • ability to change the octave of the music

It doesn't create a new music. It modifies the generated music according to the provided parameters.

Request Header: Content-Type: application/json
Request Body type: application/json
Response: music in midi format

Body must contain the fields "key", "octave_type", "which_octave"

example: 
localhost:5000/api/v1/modify

body:
{
    "key": "F#", 
    "octave_type": "higher", 
    "which_octave": 3
}

To generate sheet music

GET: /api/v1/sheet_music/<name> where name = pdf or png
Response: sheet music as a file

Sheet music is produced from the latest genereted or modified music.

eg:
 localhost:5000/api/v1/sheet_music/pdf
 returns sheet music as a pdf file
 
 localhost:5000/api/v1/sheet_music/png
 returns sheet music as a png image


To get music in mp3 format

GET: /api/v1/music_mp3 Response: music file in mp3 format

eg:
 localhost:5000/api/v1/music_mp3
 
 returns the music in mp3 format

Some tips incase of problems

Try disabling firewall if the api server is not accessible from other comupters

music-generation-api-server's People

Contributors

bipinoli avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.