Skip to main content

About

A python library which can generate sounds played by instruments mainly guitar and piano. It uses PyAudio as its dependency.

Getting Started

Pre-requisites

You just need to know basic python syntax to use this library.

Installation

If in your machine previously you have never installed PyAudio then do this:

Unix:

sudo apt-get install libasound-dev portaudio19-dev libportaudio2 libportaudiocpp0

Windows:

Download the binaries from here
Now do this
pip install PyAudio‑0.2.11‑cp39‑cp39m‑win_amd64.whl

Then
python3 -m pip install PyMusic-Instrument

Usage

Playing piano notes.

from Instrument import Instrument

piano = Instrument(bit_rate = 44100)
piano.record_key(52, duration=0.3)  # C5
piano.record_chord([(52, 56, 61)], duration=0.3)  # C5 E5 A5

piano.play()
piano.close()   # Terminates PyAudio

Playing guitar strings.

guitar = Instrument(44100)
guitar.record_key(25, duration=0.5)  # A
guitar.play()
guitar.clear_sample()  # clears the sample
guitar.close()

You can look at here the key numbers for corresponding frequency.

Alternatively you can also plot the graph

import matplotlib.pyplot as plt

key_colors = {40: ["red", 1], 42: ["blue", 1], 44: ["green", 1], 45: ["gray", 1],
                  47: ["orange", 1], 35: ["purple", 1], ((51, 56, 61),): ['black', 1]}

# piano.graphing sample contains key, time take as an array, wave equation as an array.
for key, time, wave in piano.graphing_sample:
    if key_colors[key][1]:
        plt.plot(time, wave, label=key, color=key_colors[key][0])
        key_colors[key][1] = 0
    else:
        plt.plot(time, wave, color=key_colors[key][0])

plt.show()

Or the spectogram

import librosa.display

amplitude = librosa.stft(piano.sample)
db = librosa.amplitude_to_db(abs(amplitude))
plt.figure(figsize=(14, 5))
librosa.display.specshow(db, sr=44100, x_axis='time', y_axis='hz')
plt.colorbar()
plt.show()

Documentation

https://pymusic-instrument.readthedocs.io/en/latest/

Metadata

Release files for PyMusic-Instrument 0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for PyMusic-Instrument 0.5
File Size Uploaded Provenance Actions
PyMusic-Instrument-0.5.tar.gz 5.5 kB Without provenance Details for PyMusic-Instrument-0.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for PyMusic-Instrument 0.5
File Interpreter ABI Platform Actions
PyMusic_Instrument-0.5-py3-none-any.whl Python 3 none any Details for PyMusic_Instrument-0.5-py3-none-any.whl

Total release size: 11.7 kB

Release files / PyMusic-Instrument-0.5.tar.gz

Download URL PyMusic-Instrument-0.5.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c0b8fb2594a033b4c504605932bdce450eae4fee2afdf7dd62e0f79dddb8ea84
BLAKE2b-256 checksum
How to use checksums
9a9caff8bd572978cff0ba07f90050cc22ff0efa7515fabcc0d626438a8fe33d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.10

Release files / PyMusic_Instrument-0.5-py3-none-any.whl

Download URL PyMusic_Instrument-0.5-py3-none-any.whl
Size 6.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2eb5f8c6f22db103e36a0c53b847051e9b5f6340b8443c7fcf6079130ea0e493
BLAKE2b-256 checksum
How to use checksums
3412a62dcd65bf94f3175ca37ccfdb5a30998972b1aef784ff9ad3ac72c03e90
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.10

Security for PyMusic-Instrument 0.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.5 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page