Skip to content
Permalink
Browse files

Added audio library (from r2_control) and now and failed gate sets of…

…f a siren
  • Loading branch information...
dpoulson committed Aug 13, 2019
1 parent 3b1686c commit 6388ade46cce2eaac83b7e193bfc394bdb53f1af
Showing with 70 additions and 1 deletion.
  1. +63 −0 audio.py
  2. +3 −0 course/config.csv
  3. +4 −1 main.py
@@ -0,0 +1,63 @@
from __future__ import print_function
from __future__ import absolute_import
from future import standard_library
import glob
import random
from pygame import mixer # Load the required library
import os
import datetime
import time


class AudioLibrary(object):

def __init__(self, sounds_dir, volume):
if __debug__:
print("Initiating audio")
mixer.init()
mixer.music.set_volume(float(volume))

def TriggerSound(self, data):
if __debug__:
print("Playing %s" % data)
audio_file = "./sounds/" + data + ".mp3"
# mixer.init()
if __debug__:
print("Init mixer")
mixer.music.load(audio_file) # % (audio_dir, data))
if __debug__:
print("%s Loaded" % audio_file)
mixer.music.play()
if __debug__:
print("Play")

def ListSounds(self):
files = ', '.join(glob.glob("./sounds/*.mp3"))
files = files.replace("./sounds/", "", -1)
files = files.replace(".mp3", "", -1)
return files

def ShowVolume(self):
cur_vol = str(mixer.music.get_volume())
return cur_vol

def SetVolume(self, level):
if level == "up":
if __debug__:
print("Increasing volume")
new_level = mixer.music.get_volume() + 0.025
elif level == "down":
if __debug__:
print("Decreasing volume")
new_level = mixer.music.get_volume() - 0.025
else:
if __debug__:
print("Volume level explicitly states")
new_level = level
if new_level < 0:
new_level = 0
if __debug__:
print("Setting volume to: %s" % new_level)
mixer.music.set_volume(float(new_level))
return "Ok"

@@ -3,3 +3,6 @@ course_type,default
mot_api_key,changeme
mot_site_base,https://mot.astromech.info
app_key,SECRET
audio,enabled
audio_file_type,mp3

@@ -7,14 +7,14 @@
import urllib.request
import json
import ast
import configparser
from pathlib import Path
from collections import namedtuple
from future import standard_library
from flask import Flask, request, render_template
from flask_socketio import SocketIO, emit
import database
import broadcast
import audio

Droid = namedtuple('Droid', 'droid_uid, member_uid, name, material, weight, transmitter_type')
Driver = namedtuple('Driver', 'member_uid, name, email')
@@ -32,6 +32,8 @@
socketio = SocketIO(app)
broadcast = broadcast.BroadCaster()

audio = audio.AudioLibrary("sounds", 1)

@app.route('/')
def index():
"""GET to generate a list of endpoints and their docstrings"""
@@ -132,6 +134,7 @@ def gate_trigger(gid, value):
if request.method == 'GET':
if value == 'FAIL':
if current_run != 0 and current_state != 4:
audio.TriggerSound("woop_woop")
database.log_penalty(gid, current_run)
socketio.emit('my_response', {'data': 'PENALTY!!!'}, namespace='/comms')
socketio.emit('reload_gates', {'data': 'reload current'}, namespace='/comms')

0 comments on commit 6388ade

Please sign in to comment.
You can’t perform that action at this time.