Programm:
Code: Select all
from IPython.display import Audio
from pytube import YouTube
import numpy as np
from io import BytesIO
yt = YouTube('https://www.youtube.com/watch?v=zrqqrQmeQS4')
# getting audio stream
audioStreams = list(map(lambda streamObj: streamObj.itag, yt.streams.filter(only_audio=True)))
activeStream = yt.streams.get_by_itag(audioStreams[0])
# saving to buffer
bufferObj = BytesIO()
activeStream.stream_to_buffer(bufferObj)
# saving buffer to ndarray
bufferObj.seek(0)
points_array = np.frombuffer(bufferObj.read())
# preprocessing raw numpy data
points_array = np.round(points_array,10)
points_array[np.isinf(points_array) | np.isnan(points_array)] = 0
return Audio(points_array, rate=44.1 * 1000)