示例#1
0
def play_on_hook(self):
	stop_vu()
	audio.setrate(G.rate)
	audio.setoutgain(G.gain)
	audio.start_playing(G.data)
	G.playing = 1
	G.recbtn.enable(0)
	G.window.settimer(max(10 * len(G.data) / Rates[G.rate], 1))
示例#2
0
def main():
	audio.setrate(3)
	audio.setoutgain(0)
	w = WindowParent().create('VU Meter', (200, 100))
	v = MyVUMeter().define(w)
	v.start()
	w.realize()
	while 1:
		w.dispatch(stdwin.getevent())
示例#3
0
def record_on_hook(self):
	stop_vu()
	close_sogram()
	audio.setrate(G.rate)
	audio.setoutgain(G.nomuting * G.gain)
	audio.start_recording(BUFSIZE)
	G.recording = 1
	G.playbtn.enable(0)
	G.window.settimer(10 * BUFSIZE / Rates[G.rate])
示例#4
0
	def timer(self):
		if self.sampling:
			chunk = audio.wait_recording()
			self.sampling = 0
			nums = audio.chr2num(chunk)
			ampl = max(abs(min(nums)), abs(max(nums)))
			self.append(ampl)
		if self.enabled and not self.sampling:
			audio.setrate(self.rate)
			size = Rates[self.rate]/10
			size = size/48*48
			audio.start_recording(size)
			self.sampling = 1
		if self.sampling:
			self.parent.settimer(1)
示例#5
0
               elif optname = '-d':
                       debug.append(1)
               elif optname = '-g':
                       gain = string.atoi(optarg)
                       if not (0 < gain < 256):
                               raise optarg.error, '-g gain out of range'
               elif optname = '-r':
                       rate = string.atoi(optarg)
                       if not (1 <= rate <= 3):
                               raise optarg.error, '-r rate out of range'
               elif optname = '-a':
                       starter = audio.start_playing
                       stopper = audio.wait_playing
       #
       audio.setoutgain(gain)
       audio.setrate(rate)
       #
       if not args:
               play(starter, rate, auds.loadfp(sys.stdin))
       else:
               real_stopper = 0
               for file in args:
                       if real_stopper:
                               real_stopper()
                       play(starter, rate, auds.load(file))
                       real_stopper = stopper

def play(starter, rate, data):
       magic = data[:4]
       if magic = '0008':
               mrate = 3
示例#6
0
import audio

RATE = 8192

# Initialize the audio stuff
audio.setrate(3)
audio.setoutgain(100)  # for speaker

play = audio.write

def samp(n):
       savegain = audio.getoutgain()
       try:
               audio.setoutgain(0)
               x = raw_input('Hit Enter to sample ' + `n` + ' seconds: ')
               return audio.read(n*RATE)
       finally:
               audio.setoutgain(savegain)

def echo(s, delay, gain):
       return s[:delay] + audio.add(s[delay:], audio.amplify(s, gain, gain))

def save(s, file):
       f = open(file, 'w')
       f.write(s)

def load(file):
       return loadfp(open(file, 'r'))

def loadfp(fp):
       s = ''
示例#7
0
def main():
	#
	# Turn off scroll bars
	#
	stdwin.setdefscrollbars(0, 0)
	#
	# Set default state
	#
	G.gain = 60
	G.rate = 3
	G.nomuting = 0
	G.savefile = '@rec'
	#
	# Set default values
	#
	G.data = ''
	G.playing = 0
	G.recording = 0
	G.sogram = 0
	#
	# Parse options
	#
	optlist, args = getopt.getopt(sys.argv[1:], 'mdg:r:')
	#
	for optname, optarg in optlist:
		if 0: # (So all cases start with elif)
			pass
		elif optname == '-d':
			G.debug = 1
		elif optname == '-g':
			G.gain = string.atoi(optarg)
			if not (0 < G.gain < 256):
				raise optarg.error, '-g gain out of range'
		elif optname == '-m':
			G.nomuting = (not G.nomuting)
		elif optname == '-r':
			G.rate = string.atoi(optarg)
			if not (1 <= G.rate <= 3):
				raise optarg.error, '-r rate out of range'
	#
	if args:
		G.savefile = args[0]
	#
	# Initialize the sound package
	#
	audio.setoutgain(G.nomuting * G.gain)	# Silence the speaker
	audio.setrate(G.rate)
	#
	# Create the WindowParent and VSplit
	#
	G.window = WindowParent().create('Recorder', (0, 0))
	w = G.vsplit = VSplit().create(G.window)
	#
	# VU-meter
	#
	G.vubtn = VUMeter().define(w)
	#
	# Radiobuttons for rates
	#
	r1btn = RadioButton().definetext(w, '32 K/sec')
	r1btn.on_hook = rate_hook
	r1btn.rate = 1
	#
	r2btn = RadioButton().definetext(w, '16 K/sec')
	r2btn.on_hook = rate_hook
	r2btn.rate = 2
	#
	r3btn = RadioButton().definetext(w, '8 K/sec')
	r3btn.on_hook = rate_hook
	r3btn.rate = 3
	#
	radios = [r1btn, r2btn, r3btn]
	r1btn.group = r2btn.group = r3btn.group = radios
	for r in radios:
		if r.rate == G.rate: r.select(1)
	#
	# Other controls
	#
	G.recbtn = TimeOutToggleButton().definetext(w, 'Record')
	G.recbtn.on_hook = record_on_hook
	G.recbtn.timer_hook = record_timer_hook
	G.recbtn.off_hook = record_off_hook
	#
	G.mutebtn = CheckButton().definetext(w, 'Mute')
	G.mutebtn.select(not G.nomuting)
	G.mutebtn.hook = mute_hook
	#
	G.playbtn = TimeOutToggleButton().definetext(w, 'Playback')
	G.playbtn.on_hook = play_on_hook
	G.playbtn.timer_hook = play_timer_hook
	G.playbtn.off_hook = play_off_hook
	#
	G.gainbtn = ComplexSlider().define(w)
	G.gainbtn.settexts('  Volume: ', '  ')
	G.gainbtn.setminvalmax(0, G.gain, 255)
	G.gainbtn.sethook(gain_hook)
	#
	G.sizebtn = Label().definetext(w, `len(G.data)` + ' bytes')
	#
	#G.showbtn = PushButton().definetext(w, 'Sound-o-gram...')
	#G.showbtn.hook = show_hook
	#
	G.savebtn = PushButton().definetext(w, 'Save...')
	G.savebtn.hook = save_hook
	#
	G.quitbtn = PushButton().definetext(w, 'Quit')
	G.quitbtn.hook = quit_hook
	G.playbtn.enable(0)
	G.savebtn.enable(0)
	#G.showbtn.enable(0)
	start_vu()
	G.window.realize()
	#
	# Event loop
	#
	MainLoop()
示例#8
0
def rate_hook(self):
	G.rate = self.rate
	audio.setrate(G.rate)
示例#9
0
import audio

RATE = 8192

# Initialize the audio stuff
audio.setrate(3)
audio.setoutgain(100)	# for speaker

play = audio.write

def samp(n):
	savegain = audio.getoutgain()
	try:
		audio.setoutgain(0)
		x = raw_input('Hit Enter to sample ' + `n` + ' seconds: ')
		return audio.read(n*RATE)
	finally:
		audio.setoutgain(savegain)

def echo(s, delay, gain):
	return s[:delay] + audio.add(s[delay:], audio.amplify(s, gain, gain))

def save(s, file):
	f = open(file, 'w')
	f.write(s)

def load(file):
	return loadfp(open(file, 'r'))

def loadfp(fp):
	s = ''
示例#10
0
		hdr = ()
	if hdr:
		data_size = hdr[0]
		data = fp.read(data_size)
		# XXX this doesn't work yet, need to convert from uLAW!!!
		del fp
	else:
		del fp
		data = readfile(tempname)
	if G.debug: print len(data), 'bytes read from', tempname
	if G.busy:
		G.busy = 0
		dummy = audio.stop_playing()
	#
	# Completely reset the audio device
	audio.setrate(G.rate)
	audio.setduration(0)
	audio.setoutgain(G.gain)
	#
	if G.synchronous:
		audio.write(data)
		audio.setoutgain(0)
	else:
		try:
			audio.start_playing(data)
			G.busy = 1
		except:
			stdwin.fleep()
	del data

def readfile(filename):
示例#11
0
		elif optname = '-d':
			debug.append(1)
		elif optname = '-g':
			gain = string.atoi(optarg)
			if not (0 < gain < 256):
				raise optarg.error, '-g gain out of range'
		elif optname = '-r':
			rate = string.atoi(optarg)
			if not (1 <= rate <= 3):
				raise optarg.error, '-r rate out of range'
		elif optname = '-a':
			starter = audio.start_playing
			stopper = audio.wait_playing
	#
	audio.setoutgain(gain)
	audio.setrate(rate)
	#
	if not args:
		play(starter, rate, auds.loadfp(sys.stdin))
	else:
		real_stopper = 0
		for file in args:
			if real_stopper:
				real_stopper()
			play(starter, rate, auds.load(file))
			real_stopper = stopper

def play(starter, rate, data):
	magic = data[:4]
	if magic = '0008':
		mrate = 3
示例#12
0
def rate_hook(self):
       G.rate = self.rate
       audio.setrate(G.rate)
示例#13
0
#! /usr/bin/env python
示例#14
0
def main():
    #
    # Turn off scroll bars
    #
    stdwin.setdefscrollbars(0, 0)
    #
    # Set default state
    #
    G.gain = 60
    G.rate = 3
    G.nomuting = 0
    G.savefile = '@rec'
    #
    # Set default values
    #
    G.data = ''
    G.playing = 0
    G.recording = 0
    G.sogram = 0
    #
    # Parse options
    #
    optlist, args = getopt.getopt(sys.argv[1:], 'mdg:r:')
    #
    for optname, optarg in optlist:
        if 0:  # (So all cases start with elif)
            pass
        elif optname == '-d':
            G.debug = 1
        elif optname == '-g':
            G.gain = string.atoi(optarg)
            if not (0 < G.gain < 256):
                raise optarg.error, '-g gain out of range'
        elif optname == '-m':
            G.nomuting = (not G.nomuting)
        elif optname == '-r':
            G.rate = string.atoi(optarg)
            if not (1 <= G.rate <= 3):
                raise optarg.error, '-r rate out of range'
    #
    if args:
        G.savefile = args[0]
    #
    # Initialize the sound package
    #
    audio.setoutgain(G.nomuting * G.gain)  # Silence the speaker
    audio.setrate(G.rate)
    #
    # Create the WindowParent and VSplit
    #
    G.window = WindowParent().create('Recorder', (0, 0))
    w = G.vsplit = VSplit().create(G.window)
    #
    # VU-meter
    #
    G.vubtn = VUMeter().define(w)
    #
    # Radiobuttons for rates
    #
    r1btn = RadioButton().definetext(w, '32 K/sec')
    r1btn.on_hook = rate_hook
    r1btn.rate = 1
    #
    r2btn = RadioButton().definetext(w, '16 K/sec')
    r2btn.on_hook = rate_hook
    r2btn.rate = 2
    #
    r3btn = RadioButton().definetext(w, '8 K/sec')
    r3btn.on_hook = rate_hook
    r3btn.rate = 3
    #
    radios = [r1btn, r2btn, r3btn]
    r1btn.group = r2btn.group = r3btn.group = radios
    for r in radios:
        if r.rate == G.rate: r.select(1)
    #
    # Other controls
    #
    G.recbtn = TimeOutToggleButton().definetext(w, 'Record')
    G.recbtn.on_hook = record_on_hook
    G.recbtn.timer_hook = record_timer_hook
    G.recbtn.off_hook = record_off_hook
    #
    G.mutebtn = CheckButton().definetext(w, 'Mute')
    G.mutebtn.select(not G.nomuting)
    G.mutebtn.hook = mute_hook
    #
    G.playbtn = TimeOutToggleButton().definetext(w, 'Playback')
    G.playbtn.on_hook = play_on_hook
    G.playbtn.timer_hook = play_timer_hook
    G.playbtn.off_hook = play_off_hook
    #
    G.gainbtn = ComplexSlider().define(w)
    G.gainbtn.settexts('  Volume: ', '  ')
    G.gainbtn.setminvalmax(0, G.gain, 255)
    G.gainbtn.sethook(gain_hook)
    #
    G.sizebtn = Label().definetext(w, ` len(G.data) ` + ' bytes')
    #
    #G.showbtn = PushButton().definetext(w, 'Sound-o-gram...')
    #G.showbtn.hook = show_hook
    #
    G.savebtn = PushButton().definetext(w, 'Save...')
    G.savebtn.hook = save_hook
    #
    G.quitbtn = PushButton().definetext(w, 'Quit')
    G.quitbtn.hook = quit_hook
    G.playbtn.enable(0)
    G.savebtn.enable(0)
    #G.showbtn.enable(0)
    start_vu()
    G.window.realize()
    #
    # Event loop
    #
    MainLoop()
示例#15
0
文件: play.py 项目: mcyril/ravel-ftn
#! /usr/bin/env python