mmnode-play-sound 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/python
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2016 Philemon <mmgen-py@yandex.com>
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. """
  20. mmnode-play-sound: play a sound with controlled volume
  21. """
  22. import sys
  23. from mmgen.util import die
  24. from mmgen.node_tools.Sound import *
  25. from mmgen.share import Opts
  26. volume = 100
  27. opts_data = {
  28. 'prog_name': sys.argv[0].split('/')[-1],
  29. 'desc': 'Play a sound file at controlled volume',
  30. 'usage': '[opts]',
  31. 'options': """
  32. -h, --help Print this help message
  33. -v, --volume= n Adjust sound volume by percentage 'n' (default: {})
  34. """.format(volume)
  35. }
  36. opts,args = Opts.parse_opts(sys.argv,opts_data)[:2]
  37. if 'volume' in opts:
  38. volume = opts['volume']
  39. try:
  40. volume = int(volume)
  41. assert 1 <= volume <= 120
  42. except:
  43. die(1,'Sound volume must be an integer between 1 and 120')
  44. if len(args) != 1:
  45. die(1,'You must supply a sound file')
  46. try: os.stat(args[0])
  47. except: die(1,"Couldn't stat file '{}'".format(args[0]))
  48. play_sound(args[0],volume)