ScienceWiz Portal to Discovery Sound. Includes games, quizzes, videos, interactive play, and simulations that extend the content in the book and kit. Listen to the very first sounds ever recorded. Librosa.effects.pitchshift¶ librosa.effects.pitchshift (y, sr, nsteps, binsperoctave = 12, restype = 'kaiserbest',. kwargs) source ¶ Shift the pitch of a waveform by nsteps steps. A step is equal to a semitone if binsperoctave is set to 12. Parameters y np.ndarray shape=(n,). Audio time series. Sr number 0 scalar. Audio sampling rate of y. Nsteps float scalar.
- Stringed 2 8 – Shift Pitch And Manipulate Temporal Gyrus
- Stringed 2 8 – Shift Pitch And Manipulate Temporal Arteritis
- Stringed 2 8 – Shift Pitch And Manipulate Temporal Objects
pretty_midi
contains utility function/classes for handling MIDI data,so that it’s in a format from which it is easy to modify and extractinformation.If you end up using pretty_midi
in a published research project, pleasecite the following report:Pitch manipulation. Shift from µ (r) to!, wemust also shift from v n! Figure 6: Manipulation of temporal envelope. Steady Time Attack µ(r) Pitch r on r off Decay Steady. However, the analysis window L is different from the synthesis window. L length sound data is resampled to L' length. If L L', a higher pitch sound will be produced, while L pitch sound will be produced. 2, when the pitch process is finished, the length of the sound file is the same. A higher pitch sound is produced. These studies all support the proposition that pitch and temporal duration are interacting features encoded in a multidimensional spatial array, presumably located in ASTM. Our findings from Experiment 2 show that more spatially congruent music notation facilitated the cognitive manipulation of pitch-time patterns.
Colin Raffel and Daniel P. W. Ellis.Intuitive Analysis, Creation and Manipulation of MIDI Data with pretty_midi.In 15th International Conference on Music Information Retrieval Late Breakingand Demo Papers, 2014.
Example usage for analyzing, manipulating and synthesizing a MIDI file:
Example usage for creating a simple MIDI file:
Further examples can be found in the source tree’s examples directory.
pretty_midi.PrettyMIDI
¶
pretty_midi.
PrettyMIDI
(midi_file=None, resolution=220, initial_tempo=120.0)¶A container for MIDI data in an easily-manipulable format.
Parameters: | midi_file : str or file
resolution : int
initial_tempo : float
|
---|
Attributes
instruments | (list) List of pretty_midi.Instrument objects. |
key_signature_changes | (list) List of pretty_midi.KeySignature objects. |
time_signature_changes | (list) List of pretty_midi.TimeSignature objects. |
lyrics | (list) List of pretty_midi.Lyric objects. |
__init__
(midi_file=None, resolution=220, initial_tempo=120.0)¶Initialize either by populating it with MIDI data from a file orfrom scratch with no data.
get_tempo_changes
()¶Return arrays of tempo changes in quarter notes-per-minute and theirtimes.
Returns: | tempo_change_times : np.ndarray tempi : np.ndarray
|
---|
get_end_time
()¶Returns the time of the end of the MIDI object (time of the lastevent in all instruments/meta-events).
Returns: | end_time : float |
---|
estimate_tempi
()¶Return an empirical estimate of tempos and each tempo’s probability.Based on “Automatic Extraction of Tempo and Beat from ExpressivePerformance”, Dixon 2001.
Returns: | tempos : np.ndarray
probabilities : np.ndarray
|
---|
estimate_tempo
()¶Returns the best tempo estimate from
pretty_midi.PrettyMIDI.estimate_tempi()
, for convenience.Returns: | tempo : float |
---|
get_beats
(start_time=0.0)¶Returns a list of beat locations, according to MIDI tempo changes.For compound meters (any whose numerator is a multiple of 3 greaterthan 3), this method returns every third denominator note (for 6/8or 6/16 time, for example, it will return every third 8th note or16th note, respectively). For all other meters, this method returnsevery denominator note (every quarter note for 3/4 or 4/4 time, forexample).
Parameters: | start_time : float
|
---|---|
Returns: | beats : np.ndarray |
estimate_beat_start
(candidates=10, tolerance=0.025)¶Estimate the location of the first beat based on which of the firstfew onsets results in the best correlation with the onset spike train.
Parameters: | candidates : int
tolerance : float
|
---|---|
Returns: | beat_start : float
|
get_downbeats
(start_time=0.0)¶Return a list of downbeat locations, according to MIDI tempo changesand time signature change events.
Parameters: | start_time : float |
---|---|
Returns: | downbeats : np.ndarray
|
get_onsets
()¶Return a sorted list of the times of all onsets of all notes fromall instruments. May have duplicate entries.
Returns: | onsets : np.ndarray |
---|
get_piano_roll
(fs=100, times=None, pedal_threshold=64)¶Compute a piano roll matrix of the MIDI data.
Parameters: | fs : int
times : np.ndarray
pedal_threshold : int
|
---|---|
Returns: | piano_roll : np.ndarray, shape=(128,times.shape[0])
|
get_pitch_class_histogram
(use_duration=False, use_velocity=False, normalize=True)¶Computes the histogram of pitch classes.
Parameters: | use_duration : bool use_velocity : bool
normalize : bool
|
---|---|
Returns: | histogram : np.ndarray, shape=(12,)
|
get_pitch_class_transition_matrix
(normalize=False, time_thresh=0.05)¶Computes the total pitch class transition matrix of all instruments.Transitions are added whenever the end of a note is within
time_thresh
from the start of any other note.Parameters: | normalize : bool
time_thresh : float
|
---|---|
Returns: | pitch_class_transition_matrix : np.ndarray, shape=(12,12) |
get_chroma
(fs=100, times=None, pedal_threshold=64)¶Get the MIDI data as a sequence of chroma vectors.
Parameters: | fs : int
times : np.ndarray
pedal_threshold : int
|
---|---|
Returns: | piano_roll : np.ndarray, shape=(12,times.shape[0])
|
synthesize
(fs=44100, wave=<ufunc 'sin'>)¶Synthesize the pattern using some waveshape. Ignores drum track.
Parameters: | fs : int wave : function
|
---|---|
Returns: | synthesized : np.ndarray |
fluidsynth
(fs=44100, sf2_path=None)¶Synthesize using fluidsynth.
Parameters: | fs : int
sf2_path : str
|
---|---|
Returns: | synthesized : np.ndarray |
tick_to_time
(tick)¶Converts from an absolute tick to time in seconds using
self.__tick_to_time
.Parameters: | tick : int
|
---|---|
Returns: | time : float |
time_to_tick
(time)¶Converts from a time in seconds to absolute tick using
self._tick_scales
.Parameters: | time : float
|
---|---|
Returns: | tick : int |
adjust_times
(original_times, new_times)¶Adjusts the timing of the events in the MIDI object.The parameters
original_times
and new_times
define a mapping,so that if an event originally occurs at time original_times[n]
, itwill be moved so that it occurs at new_times[n]
. If events don’toccur exactly on a time in original_times
, their timing will belinearly interpolated.Parameters: | original_times : np.ndarray
new_times : np.ndarray |
---|
remove_invalid_notes
()¶Removes any notes whose end time is before or at their start time.
write
(filename)¶Write the MIDI data out to a .mid file.
Parameters: | filename : str or file
|
---|
pretty_midi.Instrument
¶
pretty_midi.
Instrument
(program, is_drum=False, name=')¶Object to hold event information for a single instrument.
Parameters: | program : int
is_drum : bool name : str
|
---|
Attributes
program | (int) The program number of this instrument. |
is_drum | (bool) Is the instrument a drum instrument (channel 9)? |
name | (str) Name of the instrument. |
notes | (list) List of pretty_midi.Note objects. |
pitch_bends | (list) List of of pretty_midi.PitchBend objects. |
control_changes | (list) List of pretty_midi.ControlChange objects. |
__init__
(program, is_drum=False, name=')¶Create the Instrument.
get_onsets
()¶Get all onsets of all notes played by this instrument.May contain duplicates.
Returns: | onsets : np.ndarray |
---|
get_piano_roll
(fs=100, times=None, pedal_threshold=64)¶Compute a piano roll matrix of this instrument.
Parameters: | fs : int
times : np.ndarray
pedal_threshold : int
|
---|---|
Returns: | piano_roll : np.ndarray, shape=(128,times.shape[0]) |
get_chroma
(fs=100, times=None, pedal_threshold=64)¶Get a sequence of chroma vectors from this instrument.
Parameters: | fs : int
times : np.ndarray
pedal_threshold : int
|
---|---|
Returns: | piano_roll : np.ndarray, shape=(12,times.shape[0]) |
get_end_time
()¶Returns the time of the end of the events in this instrument.
Returns: | end_time : float
|
---|
get_pitch_class_histogram
(use_duration=False, use_velocity=False, normalize=False)¶Computes the frequency of pitch classes of this instrument,optionally weighted by their durations or velocities.
Parameters: | use_duration : bool use_velocity : bool
normalize : bool
|
---|---|
Returns: | histogram : np.ndarray, shape=(12,)
|
get_pitch_class_transition_matrix
(normalize=False, time_thresh=0.05)¶Computes the pitch class transition matrix of this instrument.Transitions are added whenever the end of a note is within
time_tresh
from the start of any other note.Parameters: | normalize : bool
time_thresh : float
|
---|---|
Returns: | transition_matrix : np.ndarray, shape=(12,12) |
remove_invalid_notes
()¶Removes any notes whose end time is before or at their start time.
synthesize
(fs=44100, wave=<ufunc 'sin'>)¶Synthesize the instrument’s notes using some waveshape.For drum instruments, returns zeros.
Parameters: | fs : int
wave : function
|
---|---|
Returns: | synthesized : np.ndarray
|
fluidsynth
(fs=44100, sf2_path=None)¶Synthesize using fluidsynth.
Parameters: | fs : int sf2_path : str
|
---|---|
Returns: | synthesized : np.ndarray |
pretty_midi.Note
¶
pretty_midi.
Note
(velocity, pitch, start, end)¶A note event.
Parameters: | velocity : int pitch : int
start : float end : float
|
---|
__init__
(velocity, pitch, start, end)¶
get_duration
()¶Get the duration of the note in seconds.
duration
¶
pretty_midi.PitchBend
¶
pretty_midi.
PitchBend
(pitch, time)¶A pitch bend event.
Parameters: | pitch : int
time : float |
---|
__init__
(pitch, time)¶
pretty_midi.ControlChange
¶
pretty_midi.
ControlChange
(number, value, time)¶A control change event.
Parameters: | number : int value : int
time : float |
---|
__init__
(number, value, time)¶
pretty_midi.TimeSignature
¶
pretty_midi.
TimeSignature
(numerator, denominator, time)¶Container for a Time Signature event, which contains the time signaturenumerator, denominator and the event time in seconds.
Examples
Instantiate a TimeSignature object with 6/8 time signature at 3.14 seconds:
Attributes
numerator | (int) Numerator of time signature. |
denominator | (int) Denominator of time signature. |
time | (float) Time of event in seconds. |
__init__
(numerator, denominator, time)¶
pretty_midi.KeySignature
¶
pretty_midi.
KeySignature
(key_number, time)¶Contains the key signature and the event time in seconds.Only supports major and minor keys.
Examples
Instantiate a C# minor KeySignature object at 3.14 seconds:
Attributes
key_number | (int) Key number according to [0,11] Major, [12,23] minor. For example, 0 is C Major, 12 is C minor. |
time | (float) Time of event in seconds. |
__init__
(key_number, time)¶
pretty_midi.Lyric
¶
pretty_midi.
Lyric
(text, time)¶Timestamped lyric text.
Attributes
text | (str) The text of the lyric. |
time | (float) The time in seconds of the lyric. |
__init__
(text, time)¶
Utility functions¶
pretty_midi.
key_number_to_key_name
(key_number)¶Convert a key number to a key string.
Parameters: | key_number : int
|
---|---|
Returns: | key_name : str
|
pretty_midi.
key_name_to_key_number
(key_string)¶Convert a key name string to key number.
Parameters: | key_string : str
|
---|---|
Returns: | key_number : int
|
pretty_midi.
mode_accidentals_to_key_number
(mode, num_accidentals)¶Convert a given number of accidentals and mode to a key number.
Parameters: | mode : int num_accidentals : int
|
---|---|
Returns: | key_number : int |
pretty_midi.
key_number_to_mode_accidentals
(key_number)¶Converts a key number to number of accidentals and mode.
Parameters: | key_number : int
|
---|---|
Returns: | mode : int num_accidentals : int
|
pretty_midi.
qpm_to_bpm
(quarter_note_tempo, numerator, denominator)¶Converts from quarter notes per minute to beats per minute.
Parameters: | quarter_note_tempo : float numerator : int
denominator : int |
---|---|
Returns: | bpm : float
|
pretty_midi.
note_number_to_hz
(note_number)¶Convert a (fractional) MIDI note number to its frequency in Hz.
Parameters: | note_number : float |
---|---|
Returns: | note_frequency : float
|
pretty_midi.
hz_to_note_number
(frequency)¶Convert a frequency in Hz to a (fractional) note number.
Parameters: | frequency : float |
---|---|
Returns: | note_number : float
|
pretty_midi.
note_name_to_number
(note_name)¶Converts a note name in the format
'(note)(accidental)(octavenumber)'
(e.g. 'C#4'
) to MIDI notenumber.'(note)'
is required, and is case-insensitive.'(accidental)'
should be '
for natural, '#'
for sharp and'!'
or 'b'
for flat.If
'(octave)'
is '
, octave 0 is assumed.Parameters: | note_name : str |
---|---|
Returns: | note_number : int
|
Notes
Thanks to Brian McFee.
pretty_midi.
note_number_to_name
(note_number)¶Convert a MIDI note number to its name, in the format
'(note)(accidental)(octavenumber)'
(e.g. 'C#4'
).Parameters: | note_number : int
|
---|---|
Returns: | note_name : str |
Notes
Thanks to Brian McFee.
pretty_midi.
note_number_to_drum_name
(note_number)¶Converts a MIDI note number in a percussion instrument to thecorresponding drum name, according to the General MIDI standard.
Any MIDI note number outside of the valid range (note 35-81, zero-indexed)will result in an empty string.
Parameters: | note_number : int
|
---|---|
Returns: | drum_name : str
|
Notes
See http://www.midi.org/techspecs/gm1sound.php
pretty_midi.
drum_name_to_note_number
(drum_name)¶Converts a drum name to the corresponding MIDI note number for apercussion instrument. Conversion is case, whitespace, andnon-alphanumeric character insensitive.
Parameters: | drum_name : str
|
---|---|
Returns: | note_number : int |
Notes
See http://www.midi.org/techspecs/gm1sound.php
pretty_midi.
program_to_instrument_name
(program_number)¶Converts a MIDI program number to the corresponding General MIDIinstrument name.
Parameters: | program_number : int
|
---|---|
Returns: | instrument_name : str
|
Notes
See http://www.midi.org/techspecs/gm1sound.php
pretty_midi.
instrument_name_to_program
(instrument_name)¶Converts an instrument name to the corresponding General MIDI programnumber. Conversion is case, whitespace, and non-alphanumeric characterinsensitive.
Parameters: | instrument_name : str
|
---|---|
Returns: | program_number : int
|
Notes
See http://www.midi.org/techspecs/gm1sound.php
pretty_midi.
program_to_instrument_class
(program_number)¶Converts a MIDI program number to the corresponding General MIDIinstrument class.
Parameters: | program_number : int |
---|---|
Returns: | instrument_class : str
|
Notes
See http://www.midi.org/techspecs/gm1sound.php
pretty_midi.
pitch_bend_to_semitones
(pitch_bend, semitone_range=2.0)¶Convert a MIDI pitch bend value (in the range
[-8192,8191]
) to thebend amount in semitones.Parameters: | pitch_bend : int semitone_range : float
|
---|---|
Returns: | semitones : float
|
pretty_midi.
semitones_to_pitch_bend
(semitones, semitone_range=2.0)¶Convert a semitone value to the corresponding MIDI pitch bend integer.
Parameters: | semitones : float semitone_range : float
|
---|---|
Returns: | pitch_bend : int |
Released:
Library for manipulating pitch and duration in an algorithmic way, for resynthesizing speech
Project description
Questions? Comments? Feedback? Chat with us on gitter!
A library for manipulating pitch and duration in an algorithmic way, forresynthesizing speech.
This library can be used to resynthesize pitch in natural speech using pitchcontours taken from other speech samples, generated pitch contours,or through algorithmic manipulations of the source pitch contour.
Contents
1 Common Use Cases
What can you do with this library?
Apply the pitch or duration from one speech sample to another.
- alignment happens both in time and in hertz
- after the morph process, the source pitch points will be at the sameabsolute pitch and relative time as they are in the target file
- time is relative to the start and stop time of the interval beingconsidered (e.g. the pitch value at 80% of the duration of the interval).Relative time is used so that the source and target files don’t have tobe the same length.
- temporal morphing is a minor effect if the sampling frequency is highbut it can be significant when, for example, using a stylized pitchcontour with few pitch samples.
- modifications can be done between entire wav files or betweencorresponding intervals as specified in a textgrid or other annotation(indicating the boundaries of words, stressed vowels, etc.)
- the larger the file, the less useful the results are likely to bewithout using a transcript of some sort
- the transcripts do not have to match in lexical content, only in thenumber of intervals (same number of words or phones, etc.)
- modifications can be scaled (it is possible to generate a wav file witha pitch contour that is 30% or 60% between the source and target contours).
- can also morph the pitch range and average pitch independently.
- resynthesis is performed by Praat.
- pitch can be obtained from praat (such as by using praatio)or from other sources (e.g. ESPS getF0)
- plots of the resynthesis (such as the ones below) can be generated
2 Illustrative example
Consider the phrase “Mary rolled the barrel”. In the first recording(examples/mary1.wav), “Mary rolled the barrel” was said in responseto a question such as “Did John roll the barrel?”. On the other hand,in the second recording (examples/mary2.wav) the utterance was saidin response to a question such as “What happened yesterday”.
“Mary” in “mary1.wav” is produced with more emphasis than in “mary2.wav”.It is longer and carries a more drammatic pitch excursion. UsingProMo, we can make mary1.wav spoken similar to mary2.wav, eventhough they were spoken in a different way and by different speakers.
Duration and pitch carry meaning. Change these, and you can change themeaning being conveyed.
Note that modifying pitch and duration too much can introduce artifacts.Such artifacts can be heard even in pitch morphing mary1.wav to mary2.wav.
Pitch morphing (examples/pitch_morph_example.py):
The following image shows morphing of pitch from mary1.wav to mary2.wavon a word-by-word levelin increments of 33% (33%, 66%, 100%). Note that the morph adjusts thetemporal dimension of the target signal to fit the duration of the sourcesignal (the source and generated contours are equally shorterthan the target contour). This occurs at the level of the file unlessthe user specifies an equal number of segments to align in time(e.g. using word-level transcriptions, as done here, or phone-leveltranscriptions, etc.)
With the ability to morph pitch range and average pitch, it becomes easierto morph contours produced by different speakers:
The following image shows four different pitch manipulations. On theupper left is the raw morph. Notice that final output (black line) isvery close to the target. Differences stem from duration differences.
However, the average pitch and pitch range are qualities of speech thatcan signify differences in gender in addition to other aspects ofspeaker identity. By resetting the average pitch and pitch range tothat of the source, it is possible to morph the contour while maintainingaspects of the source speaker’s identity.
The image in the upper right contains a morphfollowed by a reset of the average pitch to the source speaker’s averagepitch. In the bottom right a morph followed by a reset of the speaker’spitch range. In the bottom right pitch range was reset and then thespeaker’s average pitch was reset.
The longer the speech sample, the more representative the pitch range andmean pitch will be of the speaker. In this example both are skewed higherby the pitch accent on the first word.
Here the average pitch of the source (a female speaker) is much higherthan the target (a male speaker) and the resulting morph sounds like itcomes from a different speaker than the source or target speakers.The three recordings that involve resetting pitch range and/or averagepitch sound much more natural.
Duration morphing (examples/duration_manipulation_example.py):
The following image shows morphing of duration from mary1.wav to mary2.wavon a word-by-word basis in increments of 33% (33%, 66%, 100%).This process can operate over an entire file or, similar to pitch morphing,with annotated segments, as done in this example.
3 Tutorials
Tutorials for learning about prosody manipulation and how to use ProMo are available.
4 Major revisions
Ver 1.3 (May 29, 2017)
- added tutorials
- f0Morph() can now exclude certain regions from the morph process if desired
Ver 1.2 (January 27, 2017)
- added code for reshaping pitch accents (shift alignment, add plateau, or change height)
Ver 1.1 (February 22, 2016)
- f0 morph code for modifying speaker pitch range and average pitch
- (October 20, 2016) Added integration tests with travis CI and coveralls support.
Ver 1.0 (January 19, 2016)
- first public release.
Beta (July 1, 2013)
- first version which was utilized in my dissertation work
5 Requirements
Python 2.7.* or above
Python 3.3.* or above (or below, probably)
My praatIO library is used extensively and can be downloadedhere
Matplotlib is needed if you want to plot graphs.Matplotlib website
Stringed 2 8 – Shift Pitch And Manipulate Temporal Gyrus
Scipy is needed if you want to use interpolation–typically if you have stylizedpitch contours (in praat PitchTier format, for example) that you want to use inyour morphing).Scipy website
Matplotlib and SciPy are non-trivial to install, as they depends on several largepackages. You canvisit their websites for more information. I recommend the following instructions toinstall matplotlib which uses python wheels. These will install all requiredlibraries in one fell swoop.
On Mac, open a terminal and type:
python -m pip install matplotlib Wondershare tunesgo retro 4 9 0 download free.
python -m pip install scipy
Stringed 2 8 – Shift Pitch And Manipulate Temporal Arteritis
On Windows, open a cmd or powershell window and type:
<<path to python>> -m pip install matplotlib
<<path to python>> -m pip install scipy
e.g. C:python27python.exe -m install matplotlib
Otherwise, to manually install, after downloading the source from github, from a command-line shell, navigate to the directory containing setup.py and type:
If python is not in your path, you’ll need to enter the full path e.g.:
7 Installation
If you on Windows, you can use the installer found here (check that it is up to date though)Windows installer
Promo is on pypi and can be installed or upgraded from the command-line shell with pip like so:
Otherwise, to manually install, after downloading the source from github, from a command-line shell, navigate to the directory containing setup.py and type:
If python is not in your path, you’ll need to enter the full path e.g.:
8 Citing ProMo
If you use ProMo in your research, please cite it like so:
Tim Mahrt. ProMo: The Prosody-Morphing Library.https://github.com/timmahrt/ProMo, 2016.
9 Acknowledgements
Development of ProMo was possible thanks to NSF grant BCS 12-51343 toJennifer Cole, José I. Hualde, and Caroline Smith and to the A*MIDEX project(n° ANR-11-IDEX-0001-02) to James Sneed German funded by theInvestissements d’Avenir French Government program,managed by the French National Research Agency (ANR).
Release historyRelease notifications | RSS feed
1.3.2
1.3.1
1.3.0
1.2.6
1.2.5
1.2.3
1.2.2
1.2.1
1.2.0
1.1.1
1.1.0
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages. Instastack 1 7.
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size promo-1.3.2-py2.py3-none-any.whl (20.7 kB) | File type Wheel | Python version py2.py3 | Upload date | Hashes |
Filename, size promo-1.3.2.tar.gz (21.7 kB) | File type Source | Python version None | Upload date | Hashes |
Hashes for promo-1.3.2-py2.py3-none-any.whl
Algorithm | Hash digest |
---|---|
SHA256 | 78aedbc9ed617ceb4920b794ce0d2ada435bd7a63df9fc3c33e119ed198b607b |
MD5 | 4cef8e0e5ccca390463bfd2ddddd7743 |
BLAKE2-256 | 698dcc2871f3d1f79d71a40e25d7d0403bc567579c7c80c2f105444fe3c12ff7 |
Stringed 2 8 – Shift Pitch And Manipulate Temporal Objects
Hashes for promo-1.3.2.tar.gz
Algorithm | Hash digest |
---|---|
SHA256 | 57f624184dd200fddf8bf53eb2360f5a4cffb56d37a9feb0f7ffee6a31c4d6e7 |
MD5 | 3d110d132ee601a0ddd078407dec982b |
BLAKE2-256 | 6b158931d874183a097e9017e702b373192f4ecb78c6b2fb3da4ad767c1e699c |