本文整理汇总了Python中AppKit.NSSound类的典型用法代码示例。如果您正苦于以下问题:Python NSSound类的具体用法?Python NSSound怎么用?Python NSSound使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NSSound类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
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: executeCapture
def executeCapture(self):
self.photoView.setHidden_(False)
self.captureView.setHidden_(True)
self.previewButton.setHidden_(False)
self.countdownCheckbox.setHidden_(True)
self.captureButton.setHidden_(True)
self.useButton.setEnabled_(True)
if self.captureSession is not None:
self.captureImage()
NSSound.soundNamed_("Grab").play()
self.captureSession.stopRunning()
示例3: executeTimerCapture_
def executeTimerCapture_(self, timer):
if self.countdown_counter == 1:
self.executeCapture()
self.countdownProgress.stopAnimation_(None)
self.countdownCheckbox.setHidden_(True)
self.countdownProgress.setHidden_(True)
self.timer.invalidate()
self.timer = None
else:
self.countdown_counter = self.countdown_counter - 1
NSSound.soundNamed_("Tink").play()
self.countdownProgress.setDoubleValue_(self.countdown_counter)
示例4: __init__
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)
示例5: _playsoundOSX
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())
示例6: play
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)
示例7: mac_play
def mac_play(self, path):
"""
play a sound using mac api
"""
macsound = NSSound.alloc()
macsound.initWithContentsOfFile_byReference_(path, True)
macsound.play()
示例8: do_play
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()
示例9: __init__
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)
示例10: generate
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)
示例11: play_path
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])
示例12: present
def present(self):
"""Present the Alert, giving up after configured time..
Returns: Int result code, based on PyObjC enums. See NSAlert
Class reference, but result should be one of:
User clicked the cancel button:
NSAlertFirstButtonReturn = 1000
Alert timed out:
NSRunAbortedResponse = -1001
"""
if self.timer:
NSRunLoop.currentRunLoop().addTimer_forMode_(self.timer, NSModalPanelRunLoopMode)
# Start a Cocoa application by getting the shared app object.
# Make the python app the active app so alert is noticed.
app = NSApplication.sharedApplication()
app.activateIgnoringOtherApps_(True)
if self.alert_sound:
sound = NSSound.soundNamed_(self.alert_sound).play()
result = self.runModal() # pylint: disable=no-member
print result
return result
示例13: main
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
示例14: start_record
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()
示例15: play
def play(self):
self.ns_sound = NSSound.alloc()
self.ns_sound.initWithContentsOfFile_byReference_(self.path, True)
self.ns_sound.play()