Quantcast
Viewing all articles
Browse latest Browse all 14040

How can I convert an AudioSegment to a NumPy array and back?

As the title states, I have had difficulty converting a PyDub AudioSegment to a NumPy array and back. I am aware of how to convert a PyDub AudioSegment to a NumPy array, and have a hazy idea of how to convert a NumPy array to a PyDub AudioSegment, but the methods I have learned of are varied and do not pair with eachother. So, how could I reliably get an AudioSegment to an array and back?

This is the code I used to get the array:

audio= AudioSegment.from_file("/file/path/sillysong.wav")data = audio.get_array_of_samples()data = np.array(data)data = data.reshape(audio.channels, -1, order='F')data

I do not know how to get the array in this form back. For context, I am using TensorFlow and I need the data to be in array form. Thank you for your help! (I'm a new coder so there's probably something obvious I'm missing.)


Viewing all articles
Browse latest Browse all 14040

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>