Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
multirecord.py
import sound
import ui
from math import floor
class RecorderView(ui.View):
'''simple metering view, attached to a recorder'''
def __init__(self, filename, *args,**kwargs):
ui.View.__init__(self,*args,**kwargs)
self.r=sound.Recorder(filename)
self.filename=filename
self.p=ui.Path()
self.bg_color='yellow'
@ui.in_background
def start(self):
self.r.record()
@ui.in_background
def stop(self):
self.r.stop()
self.p=ui.Path()
#do something here... voice recog
#speech.recognize(self.filename)
def draw(self):
y=self.r.meters['average'][0]
self.p.line_to(self.r.current_time*100,(-y))
self.p.stroke()
H=50
class MultiRecorder(ui.View):
def __init__(self,Nrecorders=3, T=3):
self.r=[RecorderView('test'+str(i)+'.m4a',frame=(0,H+i*H,100*T,44)) for i in range(Nrecorders)]
for r in self.r:
self.add_subview(r)
self.N=Nrecorders
self.update_interval=1/20
self.idx=0
self.cycle_frames=floor(T/self.update_interval/(Nrecorders-1))
self.t=0
def will_close(self):
[r.stop() for r in self.r]
def update(self):
if self.t%self.cycle_frames==0:
self.r[self.idx-1].start()
self.r[self.idx].stop()
# do something with 'test'+str(i)+'.wav'
self.idx=(self.idx+1)%self.N
for r in self.r:
r.set_needs_display()
self.t+=1
v=MultiRecorder()
v.frame=(0,0,500,400)
v.bg_color='white'
v.present('sheet')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.