-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaudio.py
81 lines (73 loc) · 2.9 KB
/
audio.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import pygame
import random
from time import sleep
from config import *
#global variables
file_path = "sounds/"
file_ext = ".wav"
speaker_volume = .10
prev_sound = "null"
def play_audio(file_name):
pygame.mixer.init()
pygame.mixer.music.set_volume(speaker_volume)
pygame.mixer.music.load(file_path + file_name + file_ext)
pygame.mixer.music.play()
return
def play_audio_loop(file_name, loop):
pygame.mixer.init()
pygame.mixer.music.set_volume(speaker_volume)
pygame.mixer.music.load(file_path + file_name + file_ext)
pygame.mixer.music.play(loop)
return
#This Pi came with a copy of the seinfeld theme song lol
def play_seinfeld():
pygame.mixer.init()
pygame.mixer.music.set_volume(1)
pygame.mixer.music.load("sounds/SeinfeldTheme.mp3")
pygame.mixer.music.play()
return
def play_finding():
#Pick random path and play sound
global prev_sound
sounds = ["is_anyone_there", "hi_question", "who's_there", "come_over_here", "hello_question", "canvasing", "searching"]
sound = sounds[random.randrange(0, len(sounds))]
while sound == prev_sound: sound = sounds[random.randrange(0, len(sounds))] # Don't repeat ourselves
prev_sound = sound
if AUDIO_DEBUG: print(sound_path)
play_audio(sound)
return
def play_found():
#Pick random path and play sound
global prev_sound
sounds = ["acquired", "i_see_you", "ahahaha", "firing", "gotcha", "hello", "hellooo", "there_you_are", "hold_still"]
sound = sounds[random.randrange(0, len(sounds))]
while sound == prev_sound: sound = sounds[random.randrange(0, len(sounds))] # Don't repeat ourselves
prev_sound = sound
if AUDIO_DEBUG: print(sound_path)
play_audio(sound)
while pygame.mixer.music.get_busy() == True: continue #CHECK TO SEE IF BUSY
play_audio("turret_fire") #Play firing sound
while pygame.mixer.music.get_busy() == True: continue #CHECK TO SEE IF BUSY
return
#This is a MUCH better way to print from queue, an array of strings
def play_bye():
#Pick random path and play sound
global prev_sound
sounds= ["goodbye","goodnight","hibernating","resting","nap_time","sleep_mode_activated"]
sound = sounds[random.randrange(0, len(sounds))]
while sound == prev_sound: sound = sounds[random.randrange(0, len(sounds))] # Don't repeat ourselves
prev_sound = sound
play_audio(sound)
while pygame.mixer.music.get_busy() == True: continue #CHECK TO SEE IF BUSY
return
def play_picked_up():
#Pick random path and play sound
global prev_sound
sounds = ["help","whoa","wheee","please_put_me_down","put_me_down"]
sound = sounds[random.randrange(0, len(sounds))]
while sound == prev_sound: sound = sounds[random.randrange(0, len(sounds))] # Don't repeat ourselves
prev_sound = sound
if AUDIO_DEBUG: print(sound)
play_audio(sound)
while pygame.mixer.music.get_busy() == True: continue #CHECK TO SEE IF BUSY
return