Actually, my question is in the subject.
Closed due to the fact that the essence of the issue is incomprehensible by the participants of Streletz , VenZell , cheops , Kromster , user194374 9 Jun '16 at 6:00 .
Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .
|
1 answer
For example, I use pyglet with the avbin library avbin :
def play(file_name): import pyglet import os dll_file_name = os.path.join(os.path.dirname(__file__), 'avbin') pyglet.lib.load_library(dll_file_name) player = pyglet.media.Player() source = pyglet.media.load(file_name) player.queue(source) player.play() def update(dt): if not player.playing: # Отпишем функцию, иначе при повторном вызове, иначе # будет двойной вызов при следующем воспроизведении pyglet.clock.unschedule(update) pyglet.app.exit() # Every 500 ms / 0.5 sec pyglet.clock.schedule_interval(update, 0.5) pyglet.app.run() play('speak.mp3') The algorithm is quite simple:
- create player object
- media source creation
- adding it to the player queue
- start up player and
pygletevent loop - so that the script does not freeze after the end of playback, a scheduler is created, which every half second calls the function
- the scheduler function checks the player for activity and if it has finished playing, it unsubscribes from the scheduler and kills the event loop.
A working example (only for windows due to avbin.dll , however avbin is a cross-platform library, so this is a problem) can be viewed on my github page.
|