本文整理汇总了Python中AppKit.NSSound.alloc方法的典型用法代码示例。如果您正苦于以下问题:Python NSSound.alloc方法的具体用法?Python NSSound.alloc怎么用?Python NSSound.alloc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AppKit.NSSound
的用法示例。
在下文中一共展示了NSSound.alloc方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from AppKit import NSSound [as 别名]
# 或者: from AppKit.NSSound import alloc [as 别名]
def __init__(self):
self.pSound = [True]
for x in range(1,5):
self.pSound.append(NSSound.alloc())
print "Loading Player %d sound." %(x,)
self.pSound[x].initWithContentsOfFile_byReference_("%s/p%d.mp3" % (sound_path, x), True)
print "Loading Error and Timeout sounds"
self.pSoundError = NSSound.alloc()
self.pSoundError.initWithContentsOfFile_byReference_("%s/erro.mp3" % (sound_path,), True)
self.pSoundTimeOut = NSSound.alloc()
self.pSoundTimeOut.initWithContentsOfFile_byReference_("%s/timeout.mp3" % (sound_path,), True)
示例2: __init__
# 需要导入模块: from AppKit import NSSound [as 别名]
# 或者: from AppKit.NSSound import alloc [as 别名]
def __init__(self):
self.root = None
self.keycode = 0
self.modifiers = 0
self.activated = False
self.observer = None
self.acquire_key = 0
self.acquire_state = HotkeyMgr.ACQUIRE_INACTIVE
self.tkProcessKeyEvent_old = None
self.snd_good = NSSound.alloc().initWithContentsOfFile_byReference_(join(config.respath, 'snd_good.wav'), False)
self.snd_bad = NSSound.alloc().initWithContentsOfFile_byReference_(join(config.respath, 'snd_bad.wav'), False)
示例3: _playsoundOSX
# 需要导入模块: from AppKit import NSSound [as 别名]
# 或者: from AppKit.NSSound import alloc [as 别名]
def _playsoundOSX(sound, block = True):
'''
Utilizes AppKit.NSSound. Tested and known to work with MP3 and WAVE on
OS X 10.11 with Python 2.7. Probably works with anything QuickTime supports.
Probably works on OS X 10.5 and newer. Probably works with all versions of
Python.
Inspired by (but not copied from) Aaron's Stack Overflow answer here:
http://stackoverflow.com/a/34568298/901641
I never would have tried using AppKit.NSSound without seeing his code.
'''
from AppKit import NSSound
from Foundation import NSURL
from time import sleep
if '://' not in sound:
if not sound.startswith('/'):
from os import getcwd
sound = getcwd() + '/' + sound
sound = 'file://' + sound
url = NSURL.URLWithString_(sound)
nssound = NSSound.alloc().initWithContentsOfURL_byReference_(url, True)
if not nssound:
raise IOError('Unable to load sound named: ' + sound)
nssound.play()
if block:
sleep(nssound.duration())
示例4: play
# 需要导入模块: from AppKit import NSSound [as 别名]
# 或者: from AppKit.NSSound import alloc [as 别名]
def play(self, fp):
from AppKit import NSSound
sound = NSSound.alloc()
sound.initWithContentsOfFile_byReference_(fp.name, True)
sound.play()
while sound.isPlaying():
time.sleep(1)
示例5: mac_play
# 需要导入模块: from AppKit import NSSound [as 别名]
# 或者: from AppKit.NSSound import alloc [as 别名]
def mac_play(self, path):
"""
play a sound using mac api
"""
macsound = NSSound.alloc()
macsound.initWithContentsOfFile_byReference_(path, True)
macsound.play()
示例6: do_play
# 需要导入模块: from AppKit import NSSound [as 别名]
# 或者: from AppKit.NSSound import alloc [as 别名]
def do_play(self):
if self.playing or not self.queue:
return
self.playing = True
sample = self.queue[0]
del self.queue[0]
self.impl = NSSound.alloc()
data = NSData.alloc().initWithBytes_length_(sample, len(sample))
self.impl.initWithData_(data)
self.impl.setDelegate_(self)
self.impl.play()
示例7: __init__
# 需要导入模块: from AppKit import NSSound [as 别名]
# 或者: from AppKit.NSSound import alloc [as 别名]
def __init__(self):
self.root = None
self.keycode = 0
self.modifiers = 0
self.activated = False
self.observer = None
self.acquire_key = 0
self.acquire_state = HotkeyMgr.ACQUIRE_INACTIVE
self.tkProcessKeyEvent_old = None
if getattr(sys, 'frozen', False):
respath = normpath(join(dirname(sys.executable), os.pardir, 'Resources'))
elif __file__:
respath = dirname(__file__)
else:
respath = '.'
self.snd_good = NSSound.alloc().initWithContentsOfFile_byReference_(join(respath, 'snd_good.wav'), False)
self.snd_bad = NSSound.alloc().initWithContentsOfFile_byReference_(join(respath, 'snd_bad.wav'), False)
示例8: generate
# 需要导入模块: from AppKit import NSSound [as 别名]
# 或者: from AppKit.NSSound import alloc [as 别名]
def generate(self, text, host="", name="Morse" ):
tmpdir = mkdtemp()
try:
filename = os.path.join(tmpdir, "objc.wav")
fd = open(filename, 'wb')
self.bytesForStr( text ).tofile(fd)
fd.close()
player = NSSound.alloc()
try:
player.initWithContentsOfFile_byReference_(filename, False)
player.play()
sleep(player.duration() + 1)
finally:
del player
finally:
rmtree(tmpdir)
示例9: play_path
# 需要导入模块: from AppKit import NSSound [as 别名]
# 或者: from AppKit.NSSound import alloc [as 别名]
def play_path(self, soundPath):
if os.name == "nt":
winsound.PlaySound(soundPath,
winsound.SND_FILENAME | winsound.SND_ASYNC)
elif os.name == "posix":
if self.canGstreamer:
loc = "file://" + soundPath
self.player.set_property('uri', loc)
self.player.set_state(gst.STATE_PLAYING)
elif self.isMac:
macsound = NSSound.alloc()
macsound.initWithContentsOfFile_byReference_( \
soundPath, True)
macsound.play()
while macsound.isPlaying():
pass
else:
# os.popen4(self.command + " " + soundPath)
subprocess.Popen([self.command, soundPath])
示例10: main
# 需要导入模块: from AppKit import NSSound [as 别名]
# 或者: from AppKit.NSSound import alloc [as 别名]
def main():
# Play a sound
snd = "paper_shredder.wav"
sound = NSSound.alloc()
#sound.initWithContentsOfFile_byReference_('/Users/aleray/Desktop/Paper Shredder.app/Contents/Resources/paper_shredder.wav', True)
sound.play()
meter = EasyDialogs.ProgressBar('Compressing your images...',
maxval=100,
label='Starting',
)
for i in xrange(1, 101):
phase = '%d %% Completed' % i
print phase
meter.label(phase)
meter.inc()
time.sleep(0.01)
print 'Done with loop'
time.sleep(1)
del meter
print 'The dialog should be gone now'
for infile in sys.argv[1:]:
fileName = os.path.basename(sys.argv[1]).split(".")[0]
fileExt = os.path.basename(sys.argv[1]).split(".")[1]
outfile = "/Users/aleray/Recycled/Image Compression 1/%s.compressed.%s" % (fileName, fileExt)
if infile != outfile:
try:
im = Image.open(infile)
xsize, ysize = im.size
ysize = ysize/20
im = im.resize([xsize, ysize])
print im.size
im.save(outfile, "JPEG")
im.show()
except IOError:
print "cannot create thumbnail for", infile
示例11: start_record
# 需要导入模块: from AppKit import NSSound [as 别名]
# 或者: from AppKit.NSSound import alloc [as 别名]
def start_record(self):
if self.progress == 30:
print 'No more question'
return 0
if self.object1.poorSignal!=0:
print 'signal is poor:'+str(self.object1.poorSignal)
self.text.insert(INSERT, 'bad signal\n')
self.sta_btn['state'] = 'normal'
else:
delta = []
midgamma = []
lowgamma = []
theta = []
highalpha = []
lowalpha = []
highbeta = []
lowbeta = []
self.text.insert(INSERT,'\n\n')
self.text.insert(INSERT, 'progress:'+str(self.progress)+':\n')
self.text.insert(INSERT, 'question:'+str(self.audio_seq[self.progress])+':\n')
self.text.see(END)
print str(self.audio_seq[self.progress])
sound = NSSound.alloc()
sound.initWithContentsOfFile_byReference_(str(doc_id)+'-'+str(self.audio_seq[self.progress])+'.mp3', True)
sound.play()
for i in range(0,RECORD_TIME):
if self.object1.poorSignal!=0:
print "because signal("+str(self.object1.poorSignal)+") is bad, we skip this round."
break
else:
delta.append(self.object1.delta)
midgamma.append(self.object1.midGamma)
lowgamma.append(self.object1.lowGamma)
theta.append(self.object1.theta)
highalpha.append(self.object1.highAlpha)
lowalpha.append(self.object1.lowAlpha)
highbeta.append(self.object1.highBeta)
lowbeta.append(self.object1.lowBeta)
print 'delta:'+str(self.object1.delta)
print 'theta:'+str(self.object1.theta)
print 'highalpha:'+str(self.object1.highAlpha)
print 'midgamma:'+str(self.object1.midGamma)
print 'recording'
print self.object1.poorSignal
time.sleep(1)
sound.stop()
if len(delta)==RECORD_TIME:
self.row_data.append(delta)
self.row_data.append(theta)
self.row_data.append(lowalpha)
self.row_data.append(highalpha)
self.row_data.append(lowbeta)
self.row_data.append(highbeta)
self.row_data.append(lowgamma)
self.row_data.append(midgamma)
print self.row_data
self.sta_btn['state'] = 'disabled'
self.difficulty()
else:
self.start_record()
示例12: play
# 需要导入模块: from AppKit import NSSound [as 别名]
# 或者: from AppKit.NSSound import alloc [as 别名]
def play(self):
self.ns_sound = NSSound.alloc()
self.ns_sound.initWithContentsOfFile_byReference_(self.path, True)
self.ns_sound.play()
示例13: start_record
# 需要导入模块: from AppKit import NSSound [as 别名]
# 或者: from AppKit.NSSound import alloc [as 别名]
def start_record(self):
if self.object1.poorSignal!=0:
print 'signal is poor'
self.text.insert(INSERT, 'bad signal\n')
else:
delta = []
midgamma = []
lowgamma = []
theta = []
highalpha = []
lowalpha = []
highbeta = []
lowbeta = []
self.text.insert(INSERT,'\n\n')
self.text.insert(INSERT, 'progress:'+str(self.progress)+':\n')
self.text.insert(INSERT, 'question:'+str(self.audio_seq[self.progress])+':\n')
self.text.see(END)
print str(self.audio_seq[self.progress])
sound = NSSound.alloc()
sound.initWithContentsOfFile_byReference_(str(self.audio_seq[self.progress])+'.mp3', True)
sound.play()
for i in range(0,RECORD_TIME):
if self.object1.poorSignal!=0:
print "because signal("+str(self.object1.poorSignal)+") is bad, we skip this round."
break
else:
delta.append(self.object1.delta)
midgamma.append(self.object1.midGamma)
lowgamma.append(self.object1.lowGamma)
theta.append(self.object1.theta)
highalpha.append(self.object1.highAlpha)
lowalpha.append(self.object1.lowAlpha)
highbeta.append(self.object1.highBeta)
lowbeta.append(self.object1.lowBeta)
print 'delta:'+str(self.object1.delta)
print 'theta:'+str(self.object1.theta)
print 'highalpha:'+str(self.object1.highAlpha)
print 'midgamma:'+str(self.object1.midGamma)
print 'recording'
print self.object1.poorSignal
time.sleep(1)
if len(delta)==RECORD_TIME:
#print "std(delta)="+str(int(np.std(np.array(delta))))
#print "std(midgamma)="+str(int(np.std(np.array(midgamma))))
#print "std(lowgamma)="+str(int(np.std(np.array(lowgamma))))
#print "std(theta)="+str(int(np.std(np.array(theta))))
self.row_data.append(delta)
self.row_data.append(theta)
self.row_data.append(lowalpha)
self.row_data.append(highalpha)
self.row_data.append(lowbeta)
self.row_data.append(highbeta)
self.row_data.append(lowgamma)
self.row_data.append(midgamma)
print self.row_data
self.easy_btn['state']='normal'
self.hard_btn['state']='normal'
self.sta_btn['state'] = 'disabled'
#for i in range(0,5):
# self.row_data.append(int(np.std(np.array(delta[0:RECORD_TIME-i]))))
# self.row_data.append(int(np.std(np.array(midgamma[0:RECORD_TIME-i]))))
# self.row_data.append(int(np.std(np.array(lowgamma[0:RECORD_TIME-i]))))
# self.row_data.append(int(np.std(np.array(theta[0:RECORD_TIME-i]))))
sound.stop()
示例14:
# 需要导入模块: from AppKit import NSSound [as 别名]
# 或者: from AppKit.NSSound import alloc [as 别名]
#!/usr/bin/env python
## MacOS ѕpecific
# plays an mp3 file
from AppKit import NSSound
sound = NSSound.alloc()
sound.initWithContentsOfFile_byReference_("/Users/wishi/test.mp3", True)
sound.play()
示例15: __init__
# 需要导入模块: from AppKit import NSSound [as 别名]
# 或者: from AppKit.NSSound import alloc [as 别名]
def __init__(self, file):
self._sound = NSSound.alloc()
self._sound.initWithContentsOfFile_byReference_(file, True)