Last active
August 29, 2015 14:21
-
-
Save agfor/8f71b25c798957c47b0a to your computer and use it in GitHub Desktop.
Applause volume based judging program for ChiPy Ultimate Language Shootout 2015
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#based on http://ubuntuforums.org/showthread.php?t=500337 | |
import alsaaudio, time, audioop | |
talks = """OCaml | |
R | |
Swift | |
PostScript | |
QML | |
Ruby | |
Game of Life | |
JavaScript | |
Go | |
Spreadsheets""".split('\n') | |
results = [] | |
for talk in talks: | |
raw_input("Talk Name: %s" % talk) | |
inp = alsaaudio.PCM(alsaaudio.PCM_CAPTURE,alsaaudio.PCM_NONBLOCK) | |
inp.setchannels(1) | |
inp.setrate(8000) | |
inp.setformat(alsaaudio.PCM_FORMAT_S16_LE) | |
inp.setperiodsize(160) | |
samples = [] | |
for i in range(3750): | |
l,data = inp.read() | |
if l: | |
samples.append(audioop.rms(data, 2)) | |
time.sleep(0.001) | |
result = sum(samples) / len(samples) | |
print "Average Value for", talk, ":", result | |
results.append(result) | |
for talk, result in sorted(zip(talks, results), key = lambda t: t[1]): | |
print result, talk |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment