Search code examples
pythonpyglet

Is there a way to get audio file length Python Pyglet


I am working with pyglet and was wondering if there was a way to get full audio file length? The only way of getting the time that I am aware of is the player.time function.

Code:

import pyglet

player = pyglet.media.Player()
sound = pyglet.media.load("My Movie.wav", streaming=False)
player.queue(sound)
player.play()

Solution

  • You can use the .duration property:

    sound.duration
    

    The length of the source, in seconds.

    Not all source durations can be determined; in this case the value is None.