79315025

Date: 2024-12-29 05:53:35
Score: 2
Natty:
Report link

To fix the decoding error with J.M.Arnold's answer, you will want to add bufferObj.seek(0) before you create the AudioSegment, like so.

# Using pydub to read audio data from the buffer
bufferObj.seek(0)
audio = AudioSegment.from_file(bufferObj, format="mp4")

After that, I got an error relating to the fact that the audio_array was immutable. To fix that, I made a copy with audio_array = np.copy(audio_array), like so.

# Preprocessing raw numpy data
audio_array = np.copy(audio_array)
audio_array = np.round(audio_array,10)
audio_array[np.isinf(audio_array) | np.isnan(audio_array)] = 0

Finally, I had issues with creating and displaying the Audio object. To fix these, I inserted the Transverse of the audio_array as an argument, and added a call to display, like so

# firstly I amended the IPython import to include display
from IPython.display import Audio, display 

and

# changed Audio, note the .T after audio_array
# Display the audio
display(Audio(audio_array.T, rate=sample_rate))

Apologies for posting the fixes as an answer; I don't have the reputation to comment. However I felt I should put it somewhere, as I've been looking for these fixes for about 3 hours.

Reasons:
  • Blacklisted phrase (1): to comment
  • RegEx Blacklisted phrase (1.5): I don't have the reputation to comment
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: w1nston269