Skip to content

Instantly share code, notes, and snippets.

@quave
Created October 18, 2013 14:11
Show Gist options
  • Save quave/7042137 to your computer and use it in GitHub Desktop.
Save quave/7042137 to your computer and use it in GitHub Desktop.
import pyaudio
import wave
import sys
import pyglet
CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 2
RATE = 44100
class Range:
def __init__(self, min, max):
self.min = min
self.max = max
class Tripno:
def __init__ (self):
self.heightRange = Range(-1, 1)
self.speedRange = Range(-1, 1)
self.scoreRange = Range(-sys.maxint, sys.maxint)
self.enthropyRange = Range(0, 1)
self.heght = 0
self.speed = 0
self.enthropy = 0
self.score = 0
window = None
tripno = None
audio = None
audioInputStream = None
def setupAudio():
global audio
global audioInputStream
audio = pyaudio.PyAudio()
audioInputStream = audio.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=CHUNK)
def terminateAudio():
audio.terminate()
def setupGraphics():
global window
global label
window = pyglet.window.Window()
label = pyglet.text.Label('Hello, world',
font_name='Times New Roman',
font_size=36,
x=window.width//2, y=window.height//2,
anchor_x='center', anchor_y='center')
def terminate():
terminateAudio()
def setup():
setupGraphics()
setupAudio()
global tripno
tripno = Tripno()
def update():
audioBuf = audioInputStream.read(CHUNK)
def draw():
label.draw()
setup()
@window.event
def on_draw():
update()
window.clear()
draw()
pyglet.app.run()
terminate()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment