1

I have a script that needs to play audio file (mp3) whenever an event occurs. I'm currently using omxplayer to do that. The audio file is about 300ms long and sometimes there could be very small interval between the events, as low as 10ms, but it takes a second or two for the omxplayer to start up and play it so it adds up to ~3 seconds of processing time where something like 600ms max would be acceptable..

Is there a way to play the file instantly? Maybe it's possible to pass a 'trigger' to already running omxplayer instance? Thanks!

  • What format is the audio file ? Have you tried 'aplay <file>' ? – CoderMike Sep 21 '17 at 16:37
2

A quick fix might be simply using aplay instead of omxplayer. I was able to play near-real time sounds in response to keyboard input by calling aplay from my python script. If you need better response, you may want to look into using pygame to pre-load the sounds for playback rather than reading in the file each time.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.