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.)