當前位置: 首頁>>代碼示例>>Python>>正文


Python AppKit.NSSound類代碼示例

本文整理匯總了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)
開發者ID:joaopedrogoncalves,項目名稱:quizshow,代碼行數:11,代碼來源:SoundManager.py

示例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()
開發者ID:bitsworking,項目名稱:blink-cocoa,代碼行數:11,代碼來源:PhotoPicker.py

示例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)
開發者ID:bitsworking,項目名稱:blink-cocoa,代碼行數:12,代碼來源:PhotoPicker.py

示例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)
開發者ID:tandyuk,項目名稱:EDMarketConnector,代碼行數:15,代碼來源:hotkey.py

示例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())
開發者ID:rshield,項目名稱:goreviewpartner,代碼行數:29,代碼來源:playsound.py

示例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)
開發者ID:Ryan4021,項目名稱:dotfiles,代碼行數:7,代碼來源:jws.py

示例7: mac_play

 def mac_play(self, path):
     """
     play a sound using mac api
     """
     macsound = NSSound.alloc()
     macsound.initWithContentsOfFile_byReference_(path, True)
     macsound.play()
開發者ID:MechanisM,項目名稱:emesene,代碼行數:7,代碼來源:Sounds.py

示例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()
開發者ID:elvis-epx,項目名稱:paimorse,代碼行數:11,代碼來源:audio_nsaudio.py

示例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)
開發者ID:GankisKhan,項目名稱:EDMarketConnector,代碼行數:21,代碼來源:hotkey.py

示例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)
開發者ID:docwhat,項目名稱:morse-python,代碼行數:17,代碼來源:OutObjC.py

示例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])
開發者ID:NickCis,項目名稱:Okeykoclient,代碼行數:19,代碼來源:Sound.py

示例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
開發者ID:mattlavine,項目名稱:auto_logout,代碼行數:21,代碼來源:auto_logout.py

示例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
開發者ID:aleray,項目名稱:datateb,代碼行數:39,代碼來源:ImageCompression_01.py

示例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()
開發者ID:dreampocketit,項目名稱:brainwaveCC,代碼行數:69,代碼來源:1-gui.py

示例15: play

 def play(self):
     self.ns_sound = NSSound.alloc()
     self.ns_sound.initWithContentsOfFile_byReference_(self.path, True)
     self.ns_sound.play()
開發者ID:xoconusco,項目名稱:verano16,代碼行數:4,代碼來源:osx_panel.py


注:本文中的AppKit.NSSound類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。