本文整理汇总了Python中Base.wav方法的典型用法代码示例。如果您正苦于以下问题:Python Base.wav方法的具体用法?Python Base.wav怎么用?Python Base.wav使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Base
的用法示例。
在下文中一共展示了Base.wav方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: record
# 需要导入模块: import Base [as 别名]
# 或者: from Base import wav [as 别名]
def record(seconds=None, nchan=None, fs=None, bits=None, w=None):
"""
If a wav object w is supplied, its data array w.y is replaced by newly recorded sound.
Parameters such as duration, number of channels are taken from w by default, but may
be explicitly overridden by the other arguments.
If w is not supplied, then a new wav object is constructed.
"""###
if isinstance(w,player): w = p.wav
if w == None:
if not seconds: raise ValueError, "please specify number of seconds for which to record"
if not nchan: nchan = 2
if not fs: fs = 44100
if not bits: bits = 16
w = Base.wav(fs=fs,bits=bits,nchan=nchan)
else:
if not seconds: seconds = w.duration()
if not nchan: nchan = w.channels()
if not fs: fs = int(w.fs)
if not bits: bits = w.bits
w.fs = fs
w.bits = bits # nbytes should be updated automatically
interface = grab_interface()
format = interface.get_format_from_width(w.nbytes)
nsamp = int(0.5 + seconds * float(fs))
recorder = interface.open(format=format, channels=nchan, rate=fs, input=True)
print "recording"
strdat = recorder.read(nsamp)
print "done"
recorder.close()
release_interface(interface)
w.y = w.str2dat(strdat, nsamp, nchan)
#if w.bits==8: w.__dict__.update({'signed':True, 'dtype':'<i1',})
return w
示例2: __init__
# 需要导入模块: import Base [as 别名]
# 或者: from Base import wav [as 别名]
def __init__(self, seconds=None, nchan=None, fs=None, bits=None, w=None, callback=None, packetRateHz=100):
Background.ongoing.__init__(self)
if isinstance(w,player): w = p.wav
if w == None:
if not nchan: nchan = 2
if not fs: fs = 44100
if not bits: bits = 16
w = Base.wav(fs=fs,bits=bits,nchan=nchan)
if seconds: w.y = Base.silence(round(seconds*w.fs), nchan)
else:
if not seconds: seconds = w.duration()
if not nchan: nchan = w.channels()
if not fs: fs = int(w.fs)
if not bits: bits = w.bits
w.fs = fs
w.bits = bits # nbytes should be updated automatically
self.wav = w
self.seconds = seconds
self.nchan = nchan
self.packetRateHz = packetRateHz
if callback != None:
self.handle_data = callback
self.samples_recorded = 0
self.packets_recorded = 0
示例3: open
# 需要导入模块: import Base [as 别名]
# 或者: from Base import wav [as 别名]
def open(self, w=None, dev=None):
if w == '': w = None
if isinstance(w,str): w = Base.wav(w)
if w == None: w = self.wav
self.wav = w
if self.interface == None:
self.interface = grab_interface(self.verbose)
if not self.ready(w): self.openstream(w, dev=dev)