This is a python package that turns any images into MIDI files that views the same as them

Overview

image_to_midi

This is a python package that turns any images into MIDI files that views the same as them.

This package firstly convert the image to ASCII characters by pixels in terms of gray scale, and then convert each pixel of the image to a note with a MIDI channel (0 - 15) based on the color depth of the pixel, which is corresponding to the index of the converted ASCII character of that pixel at the ASCII character set defined by the user. By default, the ASCII character set is sorted from highest to lowest density, in this standard, the deeper the color depth of a pixel is, the smaller the MIDI channel number of the note is. For example, the pixel with the lightest color of the image will map to MIDI channel 15, while the deepest color will map to MIDI channel 0.

The default ASCII character set is

[email protected]%W$E#RK&FXYI*l]}1/+i>"!~\';,`:.

For the direction of the note transformation through the images, there are basically 2 directions, one is for viewing in a DAW, and the another one is for viewing in a piano roll software with a waterfall effect (dropping from the top). You can also customize the rotation angle of the image to transform, together with whether to flip the image or not.

Note: Each pixel of the image will convert to a note with a MIDI channel based on its color depth, the deeper the pixel's color depth is, the smaller the MIDI channel number of the note it corresponds to is, you should customize the colors corresponding to MIDI channels 0 - 15 from deepest to lightest in order to get the best viewing result when you put the resulted MIDI files in DAW or piano roll software.

Installation

You can use pip to install this package, run this line in cmd/terminal to install.

pip install image_to_midi

Importing

import image_to_midi as im

Usage

Firstly we will talk about the conversion parameters of this pacakge.

This package uses a dictionary called config_dict to store the image conversion parameters, which are

  • ascii_character_set: The ASCII character set that ranges from deepest to lightest color depth. The default value is [email protected]%W$E#RK&FXYI*l]}1/+i>"!~\';,`:.

  • resize_ratio: The resize ratio of the image to convert, could be an integer or a float, the smaller it is, the larger the image will be resized to, for example, 1 is for no resizing, 0.5 is for resize as 2 times large, 2 is for resize as 2 times small. The default value is 1

  • bit_number: The bit number the image will be converted as gray scales. The default value is 8

  • image_width_ratio: the width resize ratio of the image. The default value is 1

  • image_height_ratio: the height resize ratio of the image. The default value is 1

You can change these parameters by updating the values of the corresponding keys of config_dict. For example,

im.config_dict['resize_ratio'] = 2

Then we will talk about how to convert images to MIDI files using this package. You can use image_to_midi function to convert an image to a MIDI file.

Note: the return value of this function is a musicpy's chord instance, you can use musicpy's write function to write the return value to a MIDI file.

image_to_midi(path,
              direction=0,
              max_keys=100,
              line_interval=1 / 16,
              remapping_colors=None,
              filter_value=None,
              extra_interval=0,
              adjust_scale=None,
              rotate=None,
              whole_reverse=False,
              each_line_reverse=False,
              start='C0')
  • path: the file path of the image

  • direction: there are 3 direction modes: 0, 1, other values
    0: from left to right, used in daw representation
    1: from buttom to top, used in piano roll representation
    other values: you can custom the rotation angle of the images and whether reverse the image ascii list and each line or not

  • max_keys: the maximum key number the MIDI file has, when converting the image, if the line has more pixels than this parameter, then the excess part will be cut off

  • line_interval: the duration of notes of each line of pixels of the image, the unit is bar of 4/4 time signature

  • remapping_colors: you can pass in a dictionary to remap the MIDI channel numbers to a new order of MIDI channel numbers

  • filter_value: you can set a tuple (or a list) (a, b) to filter the ASCII characters to convert which index at the ASCII character set satisfies a <= index < b

  • extra_interval: you can set this value if you want to have extra spaces between each 2 adjacent lines of notes

  • adjust_scale: adjust the notes of each line of pixels to a scale like C major, D mixolydian, it will filter out the notes that does not belong to the scale of each line of notes, this value must be a musicpy's scale instance

  • rotate: when the parameter direction is set to a value that is not 0 or 1, you can set this value to specify the rotation angle of the image to convert, the rotation angle is clockwise for positive number, counterclockwise for negative number

  • whole_reverse: when the parameter direction is set to a value that is not 0 or 1, you can set this value to specify whether to reverse the lines of pixels of the image

  • each_line_reverse: when the parameter direction is set to a value that is not 0 or 1, you can set this value to specify whetehr to reverse each line of pixels of the image

  • start: the starting note pitch of the conversion, which is the lowest note pitch of the resulted chord type, could be a string that represents a note pitch like A0, C1, or an integer for MIDI note number

You can use musicpy's write function to write the return value of this function to a MIDI file.

result = im.image_to_midi('1.jpg')
im.write(result, name='1.mid')

Some extra notes

The default starting note pitch of the conversion is C0, which corresponds to MIDI note number 12. (If it starts from 0 then we will have some notes has pitch like B-1, which cannot be shown in most DAW and piano roll softwares)

If you would like to fit the resulted MIDI files into a standard 88-key piano which has pitch range A0 to C8, it is easy to set the max_keys parameter to 88 and the start parameter to A0 when you are using image_to_midi function to get the desired result.

You can also concatenate multiple resulted chord types converted from different images to output MIDI files with multiple viewable images. The syntax of concatenating 2 chord types is chord_c = chord_a | chord_b, to concatenate a list of chord types, you can write chord_c = im.concat(list_of_chord_types, mode='|')

You might also like...
A lightweight yet powerful audio-to-MIDI converter with pitch bend detection
A lightweight yet powerful audio-to-MIDI converter with pitch bend detection

Basic Pitch is a Python library for Automatic Music Transcription (AMT), using lightweight neural network developed by Spotify's Audio Intelligence La

Automatically move or copy files based on metadata associated with the files. For example, file your photos based on EXIF metadata or use MP3 tags to file your music files.

Automatically move or copy files based on metadata associated with the files. For example, file your photos based on EXIF metadata or use MP3 tags to file your music files.

Play any song directly into your group voice chat.
Play any song directly into your group voice chat.

Telegram VCPlayer Bot Play any song directly into your group voice chat. Official Bot : VCPlayerBot | Discussion Group : VoiceChat Music Player Suppor

A python program to cut longer MP3 files (i.e. recordings of several songs) into the individual tracks.

I'm writing a python script to cut longer MP3 files (i.e. recordings of several songs) into the individual tracks called ReCut. So far there are two

Scrap electronic music charts into CSV files
Scrap electronic music charts into CSV files

musiccharts A small python script to scrap (electronic) music charts into directories with csv files. Installation Download MusicCharts.exe Run MusicC

Guide & Examples to create deeplearning gstreamer plugins and use them in your pipeline
Guide & Examples to create deeplearning gstreamer plugins and use them in your pipeline

upai-gst-dl-plugins Guide & Examples to create deeplearning gstreamer plugins and use them in your pipeline Introduction Thanks to the work done by @j

Hide Your Secret Message in any Wave Audio File.
Hide Your Secret Message in any Wave Audio File.

HiddenWave Embedding secret messages in wave audio file What is HiddenWave Hiddenwave is a python based program for simple audio steganography. You ca

This is a realtime voice translator program which gets input from user at any language and converts it to the desired language that the user asks

This is a realtime voice translator program which gets input from user at any language and converts it to the desired language that the user asks ...

Extract the songs from your osu! libary into proper mp3 form, complete with metadata and album art!
Extract the songs from your osu! libary into proper mp3 form, complete with metadata and album art!

osu-Extract Extract the songs from your osu! libary into proper mp3 form, complete with metadata and album art! Requirements python3 mutagen pillow Us

Releases(0.19)
Owner
Rainbow Dreamer
Hello everyone, I am a programmer enjoy desigining useful mathematics, statistics and music related packages. qq: 2180502841
Rainbow Dreamer
A lightweight yet powerful audio-to-MIDI converter with pitch bend detection

Basic Pitch is a Python library for Automatic Music Transcription (AMT), using lightweight neural network developed by Spotify's Audio Intelligence La

Spotify 1.4k Jan 01, 2023
Delta TTA(Text To Audio) SoftWare

Text-To-Audio-Windows Delta TTA(Text To Audio) SoftWare Info You Can Use It For Convert Your Text To Audio File You Just Write Your Text And Your End

Delta Inc. 2 Dec 14, 2021
Anaphones are like anagrams, but for sounds.

Anaphones Anaphones are like anagrams but for sounds (phonemes). Examples include: salami-awesomely, atari-tiara, and beefy-phoebe. Anaphones can be a

James Murphy 18 Nov 02, 2022
Code for paper 'Audio-Driven Emotional Video Portraits'.

Audio-Driven Emotional Video Portraits [CVPR2021] Xinya Ji, Zhou Hang, Kaisiyuan Wang, Wayne Wu, Chen Change Loy, Xun Cao, Feng Xu [Project] [Paper] G

197 Dec 31, 2022
gentle forced aligner

Gentle Robust yet lenient forced-aligner built on Kaldi. A tool for aligning speech with text. Getting Started There are three ways to install Gentle.

1.2k Dec 30, 2022
:notes: Cross-platform music player

Exaile Exaile is a music player with a simple interface and powerful music management capabilities. Features include automatic fetching of album art,

Exaile 327 Dec 19, 2022
Gammatone-based spectrograms, using gammatone filterbanks or Fourier transform weightings.

Gammatone Filterbank Toolkit Utilities for analysing sound using perceptual models of human hearing. Jason Heeris, 2013 Summary This is a port of Malc

Jason Heeris 188 Dec 14, 2022
A voice based calculator by using termux api in Android

termux_voice_calculator This is. A voice based calculator by using termux api in Android Instagram account ๐Ÿ‘‰ ๐Ÿ‘ˆ Requirements and installation Downloa

ส•ยดโ€ขแดฅโ€ข`ส”โ• ลžฤฆแปฎฮฒฤฆaฬทmฬทโ•ฃส•ยดโ€ขแดฅโ€ข`ส” 2 Apr 29, 2022
Spotifyd - An open source Spotify client running as a UNIX daemon.

Spotifyd An open source Spotify client running as a UNIX daemon. Spotifyd streams music just like the official client, but is more lightweight and sup

8.5k Jan 09, 2023
DaisyXmusic โค A bot that can play music on Telegram Group and Channel Voice Chats

DaisyXmusic โค is the best and only Telegram VC player with playlists, Multi Playback, Channel play and more

TeamOfDaisyX 34 Oct 22, 2022
Stream Music ๐ŸŽต ๐˜ผ ๐™—๐™ค๐™ฉ ๐™ฉ๐™๐™–๐™ฉ ๐™˜๐™–๐™ฃ ๐™ฅ๐™ก๐™–๐™ฎ ๐™ข๐™ช๐™จ๐™ž๐™˜ ๐™ค๐™ฃ ๐™๐™š๐™ก๐™š๐™œ๐™ง๐™–๐™ข ๐™‚๐™ง๐™ค๐™ช๐™ฅ ๐™–๐™ฃ๐™™ ๐˜พ๐™๐™–๐™ฃ๐™ฃ๐™š๐™ก ๐™‘๐™ค๐™ž๐™˜๐™š ๐˜พ๐™๐™–๐™ฉ๐™จ ๐˜ผ๐™ซ๐™–๐™ž๐™ก?

Stream Music ๐ŸŽต ๐˜ผ ๐™—๐™ค๐™ฉ ๐™ฉ๐™๐™–๐™ฉ ๐™˜๐™–๐™ฃ ๐™ฅ๐™ก๐™–๐™ฎ ๐™ข๐™ช๐™จ๐™ž๐™˜ ๐™ค๐™ฃ ๐™๐™š๐™ก๐™š๐™œ๐™ง๐™–๐™ข ๐™‚๐™ง๐™ค๐™ช๐™ฅ ๐™–๐™ฃ๐™™ ๐˜พ๐™๐™–๐™ฃ๐™ฃ๐™š๐™ก ๐™‘๐™ค๐™ž๐™˜๐™š ๐˜พ๐™๐™–๐™ฉ๐™จ ๐˜ผ๐™ซ๐™–๐™ž๐™ก?

Sadew Jayasekara 15 Nov 12, 2022
DCL - An easy to use diacritic library used for diacritic and accent manipulation.

Diacritics Library This library is used for adding, and removing diacritics from strings. Getting started Start by importing the module: import dcl DC

Kreus Amredes 6 Jun 03, 2022
Telegram Voice-Chat Bot Written In Python Using Pyrogram.

Telegram Voice-Chat Bot Telegram Voice-Chat Bot To Play Music From Various Sources In Your Group Support All linux based os. Windows Mac Diagram Requi

TheHamkerCat 314 Dec 29, 2022
live coding in python + supercollider

live coding in python + supercollider

Zack 6 Feb 06, 2022
A Python 3 script for capturing and recording a SDR stream to a WAV file (or serving it to a HTTP audio stream).

rfsoapyfile A Python 3 script for capturing and recording a SDR stream to a WAV file (or serving it to a HTTP audio stream). The script is threaded fo

4 Dec 19, 2022
Reading list for research topics in sound event detection

Sound event detection aims at processing the continuous acoustic signal and converting it into symbolic descriptions of the corresponding sound events present at the auditory scene.

Soham 64 Jan 05, 2023
Implicit neural differentiable FM synthesizer

Implicit neural differentiable FM synthesizer The purpose of this project is to emulate arbitrary sounds with FM synthesis, where the parameters of th

Andreas Jansson 34 Nov 06, 2022
An audio guide for destroying oracles in Destiny's Vault of Glass raid

prophet An audio guide for destroying oracles in Destiny's Vault of Glass raid. This project allows you to make any encounter with oracles without hav

24 Sep 15, 2022
Speech Algorithms Collections

Speech Algorithms Collections

Ryuk 498 Jan 06, 2023
Okaeri-Music is a telegram music bot project, allow you to play music on voice chat group telegram.

Okaeri-Music is a telegram bot project that's allow you to play music on telegram voice chat group

Wahyusaputra 1 Dec 22, 2021