Caution
You're reading an old version of this documentation. If you want up-to-date information, please have a look at 0.9.1.
librosa.core.tone¶
- librosa.core.tone(frequency, sr=22050, length=None, duration=None, phi=None)[source]¶
Returns a pure tone signal. The signal generated is a cosine wave.
- Parameters
- frequencyfloat > 0
frequency
- srnumber > 0
desired sampling rate of the output signal
- lengthint > 0
desired number of samples in the output signal. When both duration and length are defined, length would take priority.
- durationfloat > 0
desired duration in seconds. When both duration and length are defined, length would take priority.
- phifloat or None
phase offset, in radians. If unspecified, defaults to -np.pi * 0.5.
- Returns
- tone_signalnp.ndarray [shape=(length,), dtype=float64]
Synthesized pure sine tone signal
- Raises
- ParameterError
If frequency is not provided.
If neither length nor duration are provided.
Examples
>>> # Generate a pure sine tone A4 >>> tone = librosa.tone(440, duration=1)
>>> # Or generate the same signal using `length` >>> tone = librosa.tone(440, sr=22050, length=22050)
Display spectrogram
>>> import matplotlib.pyplot as plt >>> plt.figure() >>> S = librosa.feature.melspectrogram(y=tone) >>> librosa.display.specshow(librosa.power_to_db(S, ref=np.max), ... x_axis='time', y_axis='mel') >>> plt.show()