Python3 PySynth use to make music

Music theory

  • Sound: vibration generating body, the more the number of vibrations, the higher tone; the less vibration frequency and the bass
  • Could be heard: the human ear can hear the voice of 16-2000 per second around here
  • Musical: vibration generating rule, high and low sounds clear
  • Noise: irregular vibration is generated, it sounds obvious level
  • Music: the sound of people express thoughts and feelings through art image
  • Sound floor: do, re, mi, sol, la, (do)
  • Tonality: C, D, E, F, G, A, B

installation

pip3 install pysynth

Examples

import pysynth

Example # 1: C major

song1 = [
['c',4],['d',4],['e',4],['f',4],['g',4],['a',4],['b',4],['c5',2],['r',1],
['c3',4],['d3',4],['e3',4],['f3',4],['g3',4],['a3',4],['b3',4],['c4',2],['r',1],
['c1*', 1], ['c2*', 1], ['c3*', 1], ['c4*', 1], ['c5*', 1], ['c6*', 1], ['c7*', 1], ['c8*', 1],
]

 Python3 PySynth use to make music

Enter the following command in the Linux terminal audition

Python3 PySynth use to make music

Try Jay's sunny, bmp is 67 per minute:

import pysynth

Python3 PySynth use to make music

Chinese wind generated random melodies

import pysynth
import numpy as np
import re

# 12356 Chinese wind note first define Pentatonic That sounds more natural
Notes np.array = ([ "c4", "D4", "e4", "G4", "A4",])
# note value
durations = np.array ([1,2,4, -2, -4 , -8])

# Interspersed randomly generated accent where
Sn = []
for T in Range (16):
    n-np.random.randint = (0, len (Notes))
    Note = Notes [n-] + "*"
    sn.append (Note)

    I in Range for (np.random.randint (3,5)):
        note0 = Notes [np.random.randint (0, len (Notes))]
        sn.append (note0)
       
# note value randomly generated sequence length is formed mixed changing rhythm
DN = []
for I in Range (len (Sn)):
    DURATION = durations [np.random.randint (0, len (durations))]
    NN = Sn [I]
    dn.append (DURATION)

The time value # combined into melody notes and
Melody = tuple (ZIP (Sn, DN))
Print (Melody)

# Synthesizes the music sound file
pysynth.make_wav (melody, fn = r " linuxmi.com.wav")

print("ok")

Remarks:

'Song' is a list of tuples or a defined format is [ 'sound', length]

Note is 'a', 'g' of these; to the sharp '#' said flatted to 'b' denotes; end to octave (default quarter note); Asterisk representative of the last accent; 'R & lt' is empty.

The length of the sound represented by numbers: 1 = whole note; 2 = half note; 4 = quarter, etc.
floating point writing notes:
 1.33 = -2 floating point half note =
 2.66 = -4 floating point quarter note =
 5.33 = -8 = eighth notes floating point

 Some parameters:
 Rhythm: in beats per minute; bpm = 95
 octave shift transpose = 0; (neg down octave; POS liter octave.)
 Between the notes stop (= 0. tuplets; staccato = 0.5); PAUSE 0.05 =
 volume Boost: high volume (volume = no change 1); Boost = 1.2
 the output file name of the output file name; fn = 'pysynth_output.wav'

 其他参数:
 Influences the decay of harmonics over frequency. Lowering the value eliminates even more harmonics at high frequencies.
 Suggested range: between 3. and 5., depending on the frequency response  of speakers/headphones used
harm_max = 4.

Guess you like

Origin www.linuxidc.com/Linux/2019-09/160567.htm
Recommended