Skip to content

Instantly share code, notes, and snippets.

@agfor
Last active August 29, 2015 14:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agfor/8f71b25c798957c47b0a to your computer and use it in GitHub Desktop.
Save agfor/8f71b25c798957c47b0a to your computer and use it in GitHub Desktop.
Applause volume based judging program for ChiPy Ultimate Language Shootout 2015
#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