有没有办法获得音频文件长度 Python Pyglet

Is there a way to get audio file length Python Pyglet

我正在使用 pyglet,想知道是否有办法获得完整的音频文件长度?获得我所知道的时间的唯一方法是 player.time 函数。

代码:

import pyglet

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

您可以使用 .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.