Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

NamesJ/musicpy

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
27 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

musicpy

Musical notes, chords, scales, and keys, represented in python

See example usage in example.py

Setup

pip install numpy
pip install pyaudio

Find which key fits a known set of notes

from musicpy.key import estimate_key
from musicpy.note import G, D, B, E

known_notes = [G, D, B, E]
estimate_key(known_notes)

Find all notes for some set of chords (union)

from musicpy.chord import Gmaj, Cmin, Adim

print(Gmaj + Cmin + Adim)

Find all chord qualities (classes) that contain a known set of intervals

from musicpy.chord import get_chords_by_intervals

intervals = [4, 7] # perfect 3rd, perfect 5th
chords = get_chords_by_intervals(intervals)

for c in chords:
    print('{}: {}'.format(c.name_suffix, c.intervals))

Play a melody

import time # for delay

import musicpy.note
# Initalize audio stream
musicpy.note.init_stream()
# Initalize tones
musicpy.note.init_tones()

default_duration = 'eighth'
melody = [E3, FzGb3, G3, B3, (A3, 'quarter'), (B3, 'quarter'), A3, B3, C4,
          D4, (C4, 'eighth'), (B3, 'half')]
print('Press [CTRL]+C to stop melody')
try:
    while True:
        for tone in melody:
            if isinstance(tone, musicpy.note.Tone):
                tone.play(default_duration)
            elif isinstance(tone, tuple):
                tone, duration = tone
                tone.play(duration)
        time.sleep(0.5)
except KeyboardInterrupt as e:
    pass

# Close audio stream
musicpy.note.close_stream()

About

Musical notes, chords, scales, and keys, represented in python

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.