当前位置: 首页>>代码示例>>Python>>正文


Python NSSound.alloc方法代码示例

本文整理汇总了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)
开发者ID:joaopedrogoncalves,项目名称:quizshow,代码行数:13,代码来源:SoundManager.py

示例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)
开发者ID:tandyuk,项目名称:EDMarketConnector,代码行数:17,代码来源:hotkey.py

示例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())
开发者ID:rshield,项目名称:goreviewpartner,代码行数:31,代码来源:playsound.py

示例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)
开发者ID:Ryan4021,项目名称:dotfiles,代码行数:9,代码来源:jws.py

示例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()
开发者ID:MechanisM,项目名称:emesene,代码行数:9,代码来源:Sounds.py

示例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()
开发者ID:elvis-epx,项目名称:paimorse,代码行数:13,代码来源:audio_nsaudio.py

示例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)
开发者ID:GankisKhan,项目名称:EDMarketConnector,代码行数:23,代码来源:hotkey.py

示例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)
开发者ID:docwhat,项目名称:morse-python,代码行数:19,代码来源:OutObjC.py

示例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])
开发者ID:NickCis,项目名称:Okeykoclient,代码行数:21,代码来源:Sound.py

示例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
开发者ID:aleray,项目名称:datateb,代码行数:41,代码来源:ImageCompression_01.py

示例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()
开发者ID:dreampocketit,项目名称:brainwaveCC,代码行数:71,代码来源:1-gui.py

示例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()
开发者ID:xoconusco,项目名称:verano16,代码行数:6,代码来源:osx_panel.py

示例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()
开发者ID:dreampocketit,项目名称:brainwaveCC,代码行数:86,代码来源:gui.py

示例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()
开发者ID:opengraphix,项目名称:snippy,代码行数:12,代码来源:sound.py

示例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)
开发者ID:gm-stack,项目名称:misc,代码行数:5,代码来源:itripctl.py


注:本文中的AppKit.NSSound.alloc方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。