librosaToWave.py 813 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

import time
import matplotlib.pyplot as plt
import numpy as np
import scipy.io.wavfile as wavfile
import sounddevice
import time
import librosa
def getWave(fileName=None,b=None,sample_rate=44100):

    if b is not None:
        fileName=input("File Name: ")
        start=input("Start time: ")
        end=input("End time: ")
        sample_rate=input("Sample rate: ")
        samples, sample_rate =librosa.load(fileName,offset=float(start),duration=float(end)-float(start), sr=int(sample_rate))
    elif fileName is not None:
        samples, sample_rate =librosa.load(fileName,sr=int(sample_rate))
    else:
        fileName=input("File Name: ")
        samples, sample_rate =librosa.load(fileName, sr=int(sample_rate))
        sounddevice.play(y,sr)
    #sounddevice.play(y,sr)
    return samples, sample_rate