Wie kann man PyTube -Bufferio richtig in Numpy -Array umwandeln, das Sinuswelle darstellt?

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Wie kann man PyTube -Bufferio richtig in Numpy -Array umwandeln, das Sinuswelle darstellt?

by Anonymous » 12 Mar 2025, 02:49

Problem : Ich versuche, Audio von YouTube über PyTube herunterzuladen, speichern Sie es auf Puffer ( Ich möchte das Audio nicht retten, um zu fahren) und dann in Numpy Array umzuwandeln, um eine rohe Audiowelle zu zeichnen. Nach dem Umbau versuche ich, es wieder in Sound umzuwandeln, und anstelle von 12 Minuten Audio aus einem Video bekomme ich 12 Sekunden statische Geräusche. Wenn Sie Puffer auf .mp4 speichern, scheint alles gut zu funktionieren. Ich bin ziemlich verloren und würde mich über jede Hilfe freuen.

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)

Top