0

I understood this page to mean that queuing in pyglet provides a gapless transition between audio tracks. But when I test it out, there is a noticeable gap. Has anyone here worked with gapless audio in pyglet?

Example:

player = pyglet.media.Player()

source1 = pyglet.media.load([file1]) # adding streaming=False doesn't fix the issue

source2 = pyglet.media.load([file2])

player.queue(source1)

player.queue(source2)

player.play()

player.seek([time]) # to avoid having to wait until the end of the track. removing this doesn't fix the gap issue

pyglet.app.run()
PrimeNumbers
  • 117
  • 1
  • 8

2 Answers2

0

I would suggest you either edit your url1 and url2 into caching them locally if they're external sources. And then use Player().time to identify when you're about to reach the end. And then call player.next_source.

Or if it's local files and you don't want to programatically solve the problem you could chop up the audio files in something like Audacity to make them seamless on start/stop.

You could also experiment with having multiple players and layer them on top of each other. But if you're only interested in audio playback, there's other alternatives.

Torxed
  • 22,866
  • 14
  • 82
  • 131
  • The documentation for pyglet actually says that using player.next_source() will most likely cause gaps. What does it mean to cache the files locally? I checked the files in Audacity and they don't actually have any leading/trailing "space", so I don't think the problem is in the audio files themselves. I've tried several other libraries but none of them seemed to work either. Thanks for the reply! – PrimeNumbers Jul 05 '20 at 11:04
  • @PrimeNumbers If you could provide sample sounds, I could probably elaborate on a more detailed answer. As I don't have any audio files locally. And I assumed your files weren't local files since the variables names were `url1` hinting towards a web based resource of some sort. – Torxed Jul 05 '20 at 11:38
  • I troubleshooted this with someone on the pyglet discord, and it turns out that mp3 files are padded at the front and at the back so that was the issue. It seems to work fine for any other audio format. Thanks for the help! Also, the sources were local, naming them 'url' probably wasn't the best idea, sorry about that. – PrimeNumbers Jul 05 '20 at 14:30
0

It turns out that there were 2 problems.

The first one: I should have used

source_group = pyglet.media.SourceGroup()

source_group.add(source1)
source_group.add(source2)

player.queue(source_group)

The second one: mp3 files are apparently slightly padded at the beginning and at the end, so that is where the gap is coming from. However, this does not seem to be an issue with any other file type.

PrimeNumbers
  • 117
  • 1
  • 8