I have a script that reads an audio media file with pydub and then outputs it to a pyaudio stream. Using the code below it plays through super quickly and I only hear snippets of the audio. I believe the issue is that pydub using milliseconds and pyaudio wanting frames.
def _load_media(self, media_location) :
self.media = AudioSegment.from_file(media_location)
self.stream = self.p.open( format=self.p.get_format_from_width(self.media.sample_width),
channels=self.media.channels,
rate=self.media.frame_rate,
output=True,
stream_callback=self._load_frames)
self.media_loaded = True
def _load_frames(self, in_data, frame_count, time_info, status) :
data = self.media[:frame_count].raw_data
self.media = self.media[frame_count:]
return (data, pyaudio.paContinue)