How to create a numpy array from a pydub AudioSegment?

后端 未结 2 635
无人及你
无人及你 2021-02-18 16:43

I\'m aware of the following question: How to create a pydub AudioSegment using an numpy array?

My question is the right opposite. If I have a pydub AudioSegment how can

2条回答
  •  一生所求
    2021-02-18 17:36

    You can get an array.array from an AudioSegment then convert it to a numpy.ndarray:

    from pydub import AudioSegment
    import numpy as np
    song = AudioSegment.from_mp3('song.mp3')
    samples = song.get_array_of_samples()
    samples = np.array(samples)
    

提交回复
热议问题