Mplayer.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import logging
  2. import os
  3. import subprocess
  4. logging.basicConfig()
  5. logger = logging.getLogger("kalliope")
  6. MPLAYER_EXEC_PATH = "/usr/bin/mplayer"
  7. class Mplayer(object):
  8. """
  9. This Class is representing the MPlayer Object used to play the all sound of the system.
  10. """
  11. def __init__(self):
  12. pass
  13. @classmethod
  14. def play(cls, filepath):
  15. """
  16. Play the sound located in the provided filepath
  17. :param filepath: The file path of the sound to play
  18. :type filepath: str
  19. :Example:
  20. Mplayer.play(self.file_path)
  21. .. seealso:: TTS
  22. .. raises::
  23. .. warnings:: Class Method and Public
  24. """
  25. mplayer_exec_path = [MPLAYER_EXEC_PATH]
  26. mplayer_options = ['-slave', '-quiet']
  27. mplayer_command = list()
  28. mplayer_command.extend(mplayer_exec_path)
  29. mplayer_command.extend(mplayer_options)
  30. mplayer_command.append(filepath)
  31. logger.debug("Mplayer cmd: %s" % str(mplayer_command))
  32. fnull = open(os.devnull, 'w')
  33. subprocess.call(mplayer_command, stdout=fnull, stderr=fnull)