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


Python ossaudiodev.open方法代碼示例

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


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

示例1: audiodata

# 需要導入模塊: import ossaudiodev [as 別名]
# 或者: from ossaudiodev import open [as 別名]
def audiodata(item, start=0, end=None):
    """
    Given an item, returns a chunk of audio samples formatted into a string.
    When the fuction is called, if start and end are omitted, the entire
    samples of the recording will be returned.  If only end is omitted,
    samples from the start offset to the end of the recording will be returned.
    
    @param start: start offset
    @type start: integer (number of 16kHz frames)
    @param end: end offset
    @type end: integer (number of 16kHz frames) or None to indicate
    the end of file
    @return: string of sequence of bytes of audio samples
    """
    assert(end is None or end > start)
    headersize = 44
    fnam = os.path.join(PREFIX,item.replace(':',os.path.sep)) + '.wav'
    if end is None:
        data = open(fnam).read()
    else:
        data = open(fnam).read(headersize+end*2)
    return data[headersize+start*2:] 
開發者ID:rafasashi,項目名稱:razzy-spinner,代碼行數:24,代碼來源:timit.py

示例2: play

# 需要導入模塊: import ossaudiodev [as 別名]
# 或者: from ossaudiodev import open [as 別名]
def play(data):
    """
    Play the given audio samples.
    
    @param data: audio samples
    @type data: string of bytes of audio samples
    """
    if not PLAY_ENABLED:
        print >>sys.stderr, "sorry, currently we don't support audio playback on this platform:", sys.platform
        return

    try:
        dsp = ossaudiodev.open('w')
    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:rafasashi,項目名稱:razzy-spinner,代碼行數:19,代碼來源:timit.py

示例3: spkrinfo

# 需要導入模塊: import ossaudiodev [as 別名]
# 或者: from ossaudiodev import open [as 別名]
def spkrinfo(self, speaker):
        """
        :return: A dictionary mapping .. something.
        """
        if speaker in self._utterances:
            speaker = self.spkrid(speaker)

        if self._speakerinfo is None:
            self._speakerinfo = {}
            for line in self.open('spkrinfo.txt'):
                if not line.strip() or line[0] == ';': continue
                rec = line.strip().split(None, 9)
                key = "dr%s-%s%s" % (rec[2],rec[1].lower(),rec[0].lower())
                self._speakerinfo[key] = SpeakerInfo(*rec)

        return self._speakerinfo[speaker] 
開發者ID:rafasashi,項目名稱:razzy-spinner,代碼行數:18,代碼來源:timit.py

示例4: oss_play

# 需要導入模塊: import ossaudiodev [as 別名]
# 或者: from ossaudiodev import open [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

示例5: play

# 需要導入模塊: import ossaudiodev [as 別名]
# 或者: from ossaudiodev import open [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

示例6: spkrinfo

# 需要導入模塊: import ossaudiodev [as 別名]
# 或者: from ossaudiodev import open [as 別名]
def spkrinfo(self, speaker):
        """
        :return: A dictionary mapping .. something.
        """
        if speaker in self._utterances:
            speaker = self.spkrid(speaker)

        if self._speakerinfo is None:
            self._speakerinfo = {}
            for line in self.open('spkrinfo.txt'):
                if not line.strip() or line[0] == ';':
                    continue
                rec = line.strip().split(None, 9)
                key = "dr%s-%s%s" % (rec[2], rec[1].lower(), rec[0].lower())
                self._speakerinfo[key] = SpeakerInfo(*rec)

        return self._speakerinfo[speaker] 
開發者ID:V1EngineeringInc,項目名稱:V1EngineeringInc-Docs,代碼行數:19,代碼來源:timit.py

示例7: _prim

# 需要導入模塊: import ossaudiodev [as 別名]
# 或者: from ossaudiodev import open [as 別名]
def _prim(ext, sentences=items, offset=False):
    if isinstance(sentences,str):
        sentences = [sentences]
    for sent in sentences:
        fnam = os.path.sep.join([PREFIX] + sent.split(':')) + ext
        r = []
        for l in open(fnam):
            if not l.strip(): continue
            a = l.split()
            if offset:
                r.append((a[2],int(a[0]),int(a[1])))
            else:
                r.append(a[2])
        yield r 
開發者ID:rafasashi,項目名稱:razzy-spinner,代碼行數:16,代碼來源:timit.py

示例8: transcription_dict

# 需要導入模塊: import ossaudiodev [as 別名]
# 或者: from ossaudiodev import open [as 別名]
def transcription_dict(self):
        """
        :return: A dictionary giving the 'standard' transcription for
        each word.
        """
        _transcriptions = {}
        for line in self.open('timitdic.txt'):
            if not line.strip() or line[0] == ';': continue
            m = re.match(r'\s*(\S+)\s+/(.*)/\s*$', line)
            if not m: raise ValueError('Bad line: %r' % line)
            _transcriptions[m.group(1)] = m.group(2).split()
        return _transcriptions 
開發者ID:rafasashi,項目名稱:razzy-spinner,代碼行數:14,代碼來源:timit.py

示例9: phone_times

# 需要導入模塊: import ossaudiodev [as 別名]
# 或者: from ossaudiodev import open [as 別名]
def phone_times(self, utterances=None):
        """
        offset is represented as a number of 16kHz samples!
        """
        return [(line.split()[2], int(line.split()[0]), int(line.split()[1]))
                for fileid in self._utterance_fileids(utterances, '.phn')
                for line in self.open(fileid) if line.strip()] 
開發者ID:rafasashi,項目名稱:razzy-spinner,代碼行數:9,代碼來源:timit.py

示例10: words

# 需要導入模塊: import ossaudiodev [as 別名]
# 或者: from ossaudiodev import open [as 別名]
def words(self, utterances=None):
        return [line.split()[-1]
                for fileid in self._utterance_fileids(utterances, '.wrd')
                for line in self.open(fileid) if line.strip()] 
開發者ID:rafasashi,項目名稱:razzy-spinner,代碼行數:6,代碼來源:timit.py

示例11: word_times

# 需要導入模塊: import ossaudiodev [as 別名]
# 或者: from ossaudiodev import open [as 別名]
def word_times(self, utterances=None):
        return [(line.split()[2], int(line.split()[0]), int(line.split()[1]))
                for fileid in self._utterance_fileids(utterances, '.wrd')
                for line in self.open(fileid) if line.strip()] 
開發者ID:rafasashi,項目名稱:razzy-spinner,代碼行數:6,代碼來源:timit.py

示例12: sents

# 需要導入模塊: import ossaudiodev [as 別名]
# 或者: from ossaudiodev import open [as 別名]
def sents(self, utterances=None):
        return [[line.split()[-1]
                 for line in self.open(fileid) if line.strip()]
                for fileid in self._utterance_fileids(utterances, '.wrd')] 
開發者ID:rafasashi,項目名稱:razzy-spinner,代碼行數:6,代碼來源:timit.py

示例13: sent_times

# 需要導入模塊: import ossaudiodev [as 別名]
# 或者: from ossaudiodev import open [as 別名]
def sent_times(self, utterances=None):
        return [(line.split(None,2)[-1].strip(),
                 int(line.split()[0]), int(line.split()[1]))
                for fileid in self._utterance_fileids(utterances, '.txt')
                for line in self.open(fileid) if line.strip()] 
開發者ID:rafasashi,項目名稱:razzy-spinner,代碼行數:7,代碼來源:timit.py

示例14: audiodata

# 需要導入模塊: import ossaudiodev [as 別名]
# 或者: from ossaudiodev import open [as 別名]
def audiodata(self, utterance, start=0, end=None):
        assert(end is None or end > start)
        headersize = 44
        if end is None:
            data = self.open(utterance+'.wav').read()
        else:
            data = self.open(utterance+'.wav').read(headersize+end*2)
        return data[headersize+start*2:] 
開發者ID:rafasashi,項目名稱:razzy-spinner,代碼行數:10,代碼來源:timit.py

示例15: play

# 需要導入模塊: import ossaudiodev [as 別名]
# 或者: from ossaudiodev import open [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


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