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


Python ossaudiodev.AFMT_S16_LE屬性代碼示例

本文整理匯總了Python中ossaudiodev.AFMT_S16_LE屬性的典型用法代碼示例。如果您正苦於以下問題:Python ossaudiodev.AFMT_S16_LE屬性的具體用法?Python ossaudiodev.AFMT_S16_LE怎麽用?Python ossaudiodev.AFMT_S16_LE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在ossaudiodev的用法示例。


在下文中一共展示了ossaudiodev.AFMT_S16_LE屬性的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: oss_play

# 需要導入模塊: import ossaudiodev [as 別名]
# 或者: from ossaudiodev import AFMT_S16_LE [as 別名]
def oss_play(data, rate=44100):
    ''' Send audio array to oss for playback
    '''
    import ossaudiodev
    audio = ossaudiodev.open('/dev/audio','w')
    formats = audio.getfmts()
    if ossaudiodev.AFMT_S16_LE & formats:
        # Use 16 bit if available
        audio.setfmt(ossaudiodev.AFMT_S16_LE)
        data = encode.as_int16(data)
    elif ossaudiodev.AFMT_U8 & formats:
        # Otherwise use 8 bit
        audio.setfmt(ossaudiodev.AFMT_U8)
        data = encode.as_uint8(data)
    audio.speed(rate)
    while len(data):
        audio.write(data[:1024])
        data = data[1024:]
    audio.flush()
    audio.sync()
    audio.close() 
開發者ID:wybiral,項目名稱:python-musical,代碼行數:23,代碼來源:playback.py

示例2: play

# 需要導入模塊: import ossaudiodev [as 別名]
# 或者: from ossaudiodev import AFMT_S16_LE [as 別名]
def play(self, utterance, start=0, end=None):
        """
        Play the given audio sample.

        :param utterance: The utterance id of the sample to play
        """
        # Method 1: os audio dev.
        try:
            import ossaudiodev
            try:
                dsp = ossaudiodev.open('w')
                dsp.setfmt(ossaudiodev.AFMT_S16_LE)
                dsp.channels(1)
                dsp.speed(16000)
                dsp.write(self.audiodata(utterance, start, end))
                dsp.close()
            except IOError, e:
                print >>sys.stderr, ("can't acquire the audio device; please "
                                     "activate your audio device.")
                print >>sys.stderr, "system error message:", str(e)
            return 
開發者ID:blackye,項目名稱:luscan-devel,代碼行數:23,代碼來源:timit.py

示例3: play

# 需要導入模塊: import ossaudiodev [as 別名]
# 或者: from ossaudiodev import AFMT_S16_LE [as 別名]
def play(self, utterance, start=0, end=None):
        """
        Play the given audio sample.

        :param utterance: The utterance id of the sample to play
        """
        # Method 1: os audio dev.
        try:
            import ossaudiodev
            try:
                dsp = ossaudiodev.open('w')
                dsp.setfmt(ossaudiodev.AFMT_S16_LE)
                dsp.channels(1)
                dsp.speed(16000)
                dsp.write(self.audiodata(utterance, start, end))
                dsp.close()
            except IOError as e:
                print(("can't acquire the audio device; please "
                                     "activate your audio device."), file=sys.stderr)
                print("system error message:", str(e), file=sys.stderr)
            return
        except ImportError:
            pass

        # Method 2: pygame
        try:
            # FIXME: this won't work under python 3
            import pygame.mixer, StringIO
            pygame.mixer.init(16000)
            f = StringIO.StringIO(self.wav(utterance, start, end))
            pygame.mixer.Sound(f).play()
            while pygame.mixer.get_busy():
                time.sleep(0.01)
            return
        except ImportError:
            pass

        # Method 3: complain. :)
        print(("you must install pygame or ossaudiodev "
                             "for audio playback."), file=sys.stderr) 
開發者ID:rafasashi,項目名稱:razzy-spinner,代碼行數:42,代碼來源:timit.py

示例4: play

# 需要導入模塊: import ossaudiodev [as 別名]
# 或者: from ossaudiodev import AFMT_S16_LE [as 別名]
def play(self, utterance, start=0, end=None):
        """
        Play the given audio sample.

        :param utterance: The utterance id of the sample to play
        """
        # Method 1: os audio dev.
        try:
            import ossaudiodev

            try:
                dsp = ossaudiodev.open('w')
                dsp.setfmt(ossaudiodev.AFMT_S16_LE)
                dsp.channels(1)
                dsp.speed(16000)
                dsp.write(self.audiodata(utterance, start, end))
                dsp.close()
            except IOError as e:
                print(
                    (
                        "can't acquire the audio device; please "
                        "activate your audio device."
                    ),
                    file=sys.stderr,
                )
                print("system error message:", str(e), file=sys.stderr)
            return
        except ImportError:
            pass

        # Method 2: pygame
        try:
            # FIXME: this won't work under python 3
            import pygame.mixer, StringIO

            pygame.mixer.init(16000)
            f = StringIO.StringIO(self.wav(utterance, start, end))
            pygame.mixer.Sound(f).play()
            while pygame.mixer.get_busy():
                time.sleep(0.01)
            return
        except ImportError:
            pass

        # Method 3: complain. :)
        print(
            ("you must install pygame or ossaudiodev " "for audio playback."),
            file=sys.stderr,
        ) 
開發者ID:V1EngineeringInc,項目名稱:V1EngineeringInc-Docs,代碼行數:51,代碼來源:timit.py


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