Beispiel #1
0
def chirps(freqs, sample_rate, duration):
    signals = []
    for f1, f2 in zip(freqs, freqs[1:]):
        signals.append(
            librosa.chirp(f1,
                          f2,
                          sr=sample_rate,
                          duration=duration / len(freqs)))
    return np.concatenate(signals)
Beispiel #2
0
    def __test(fmin, fmax, sr, length, duration, linear, phi):

        y = librosa.chirp(fmin=fmin,
                          fmax=fmax,
                          sr=sr,
                          length=length,
                          duration=duration,
                          linear=linear,
                          phi=phi)

        if length is not None:
            assert len(y) == length
        else:
            assert len(y) == np.ceil(duration * sr)
Beispiel #3
0
    def __test(fmin, fmax, sr, length, duration, linear, phi):

        y = librosa.chirp(fmin=fmin,
                          fmax=fmax,
                          sr=sr,
                          length=length,
                          duration=duration,
                          linear=linear,
                          phi=phi)

        if length is not None:
            assert len(y) == length
        else:
            assert len(y) == np.ceil(duration * sr)
Beispiel #4
0
def y_chirp():
    sr = 22050
    y = librosa.chirp(55, 55 * 2**3, length=sr // 8, sr=sr)
    return y
Beispiel #5
0
def y_chirp():
    sr = 22050
    y = librosa.chirp(fmin=55, fmax=55 * 2**3, length=sr // 8, sr=sr)
    return y
# We'll also use `mir_eval` to synthesize a signal for us
import mir_eval.sonify

# %%
# Playing a synthetic sound
# -------------------------
# The IPython Audio widget accepts raw numpy data as
# audio signals.  This means we can synthesize signals
# directly and play them back in the browser.
#
# For example, we can make a sine sweep from C3 to C5:

sr = 22050

y_sweep = librosa.chirp(fmin=librosa.note_to_hz('C3'),
                        fmax=librosa.note_to_hz('C5'),
                        sr=sr,
                        duration=1)

Audio(data=y_sweep, rate=sr)

# %%
# Playing a real sound
# --------------------
# Of course, we can also play back real recorded sounds
# in the same way.
#
y, sr = librosa.load(librosa.ex('trumpet'))

Audio(data=y, rate=sr)

# %%