-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplay_audio.py
More file actions
35 lines (29 loc) · 870 Bytes
/
play_audio.py
File metadata and controls
35 lines (29 loc) · 870 Bytes
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
#!/usr/bin/env python3
# import pygame
from pygame import mixer
import time
mixer.init()
# pygame.init()
# screen = pygame.display.set_mode((640, 480), pygame.RESIZABLE)
def play_audio(vol, filename):
"""
Play the .wav file
:param vol: Volume audio is played at (0-1)
:param filename: Name of audio file (55hz.wav)
:return: None
"""
mixer.pre_init(44100, -16, 1, 512) # <-- fixes sound lag delay
mixer.init()
audio = mixer.Sound("audio/"+filename)
audio.set_volume(vol)
print('start')
audio.play()
time.sleep(1)
# while True:
# for event in pygame.event.get():
# if event.type == pygame.KEYDOWN:
# if event.key == pygame.K_ESCAPE:
# print('Quit')
# pygame.quit()
# raise SystemExit(0)
play_audio(1, 'test.wav')