Guest User

Untitled

a guest
Aug 27th, 2018
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. import pygame.mixer
  2. import RPi.GPIO as GPIO
  3. from sys import exit
  4. import random
  5. import time
  6. import glob
  7. import pygame.event
  8.  
  9.  
  10. attack = glob.glob("attack/*.wav") #folder with attack quotes
  11. move = glob.glob("movement/*.wav") #folder with move/idle quotes
  12. taunt = glob.glob("taunt/*.wav") #folder with taunt quotes
  13. joke = glob.glob("joke/*.wav") #folder with the jokes
  14. laugh = glob.glob("laugh/*.wav") #folder with the laughing tracks
  15. pick = glob.glob("pick/*.wav") #folder with pick/ban quotes
  16. misc = glob.glob("misc/*.wav")
  17.  
  18.  
  19. GPIO.setmode(GPIO.BCM)
  20. GPIO.setup(17, GPIO.IN)
  21. GPIO.setup(18, GPIO.IN)
  22. GPIO.setup(27, GPIO.IN)
  23. GPIO.setup(22, GPIO.IN)
  24. GPIO.setup(23, GPIO.IN)
  25. GPIO.setup(24, GPIO.IN)
  26. GPIO.setup(25, GPIO.IN)
  27. pygame.mixer.init(48000, -16, 1, 1024)
  28. SoundA = pygame.mixer.Channel(1)
  29. SoundB = pygame.mixer.Channel(2)
  30. SoundC = pygame.mixer.Channel(3)
  31. SoundD = pygame.mixer.Channel(4)
  32. SoundE = pygame.mixer.Channel(5)
  33. SoundF = pygame.mixer.Channel(6)
  34. SoundG = pygame.mixer.Channel(7)
  35.  
  36. attack_sounds = []
  37. for sound_file in glob.glob("attack/*.wav"):
  38. attack_sounds.append(pygame.mixer.Sound(sound_file))
  39.  
  40. move_sounds = []
  41. for sound_file in glob.glob("movement/*.wav"):
  42. move_sounds.append(pygame.mixer.Sound(sound_file))
  43.  
  44. taunt_sounds = []
  45. for sound_file in glob.glob("taunt/*.wav"):
  46. taunt_sounds.append(pygame.mixer.Sound(sound_file))
  47.  
  48. joke_sounds = []
  49. for sound_file in glob.glob("joke/*.wav"):
  50. attack_sounds.append(pygame.mixer.Sound(sound_file))
  51.  
  52. laugh_sounds = []
  53. for sound_file in glob.glob("laugh/*.wav"):
  54. laugh_sounds.append(pygame.mixer.Sound(sound_file))
  55.  
  56. pick_sounds = []
  57. for sound_file in glob.glob("pick/*.wav"):
  58. pick_sounds.append(pygame.mixer.Sound(sound_file))
  59.  
  60. misc_sounds = []
  61. for sound_file in glob.glob("misc/*.wav"):
  62. misc_sounds.append(pygame.mixer.Sound(sound_file))
  63.  
  64.  
  65. print ("Soundboard aktiv.");
  66.  
  67. while True:
  68.  
  69. try:
  70. if (GPIO.input(17) == True):
  71. random_sound = random.choice(attack_sounds)
  72. random_sound.play()
  73.  
  74. if (GPIO.input(18) == True):
  75. random_sound = random.choice(move_sounds)
  76. random_sound.play()
  77.  
  78. if (GPIO.input(27) == True):
  79. random_sound = random.choice(taunt_sounds)
  80. random_sound.play()
  81.  
  82. if (GPIO.input(22) == True):
  83. random_sound = random.choice(joke_sounds)
  84. random_sound.play()
  85.  
  86. if (GPIO.input(23) == True):
  87. random_sound = random.choice(laugh_sounds)
  88. random_sound.play()
  89.  
  90. if (GPIO.input(24) == True):
  91. random_sound = random.choice(pick_sounds)
  92. random_sound.play()
  93.  
  94. if (GPIO.input(25) == True):
  95. random_sound = random.choice(misc_sounds)
  96. random_sound.play()
  97.  
  98.  
  99. except KeyboardInterrupt:
  100. exit()
  101. time.sleep(2)
Add Comment
Please, Sign In to add comment