mmnode-play-sound 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2020 The MMGen Project <mmgen@tuta.io>
  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.common import *
  24. from mmgen.util import die
  25. from mmgen.node_tools.Sound import *
  26. volume = 100
  27. opts_data = {
  28. 'text': {
  29. 'desc': 'Play a sound file at controlled volume',
  30. 'usage': '[opts]',
  31. 'options': """
  32. -h, --help Print this help message
  33. -t, --testing Test, don't execute shell commands
  34. -v, --volume= n Adjust sound volume by percentage 'n' (default: {})
  35. """.format(volume)
  36. }
  37. }
  38. args = opts.init(opts_data)
  39. if opt.volume:
  40. try:
  41. assert 1 <= int(opt.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],int(opt.volume),testing=opt.testing)