Mplayer.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 synapses_list: String
  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)