I'm reading a file in Python using either of librosa, wave or soundfile libraries and I need to push the chunk (any size) to a HTTP stream. By specification, stream string input requires me to convert frames into RAW s16le format.
I tried multiple options including:
soundarray,rate = librosa.load(pathToWavFile, dtype="
str = b''.join(soundarray)
But this just creates an empty audio stream. What am I doing wrong?
解决方案
You can try pydub to convert audio to audio-segment, split audio-segment into chunks that are playable (i.e you can play each chunk), then convert them to raw as needed.
Here is a quick code.
from pydub import AudioSegment
from pydub.utils import make_chunks
myaudio = AudioSegment.from_file("myaudio.wav" , "wav")
chunk_length_ms = 1000 # pydub c