File size: 400 Bytes
4d96acb
2e66664
 
 
 
46ec003
 
2e66664
 
 
 
 
46ec003
1
2
3
4
5
6
7
8
9
10
11
12
13
from pytubefix import YouTube
import librosa
import numpy as np

def download_youtube_audio(url):
    # yt = YouTube(url, use_po_token=True)
    yt = YouTube(url)
    stream = yt.streams.filter(only_audio=True).first()
    filename = stream.download()
    audio, sr = librosa.load(filename, sr=44100, mono=False)
    if audio.ndim == 1:
        audio = np.stack([audio, audio])
    return audio.T, sr