本文整理汇总了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:]
示例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
示例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]
示例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()
示例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
示例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]
示例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
示例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
示例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()]
示例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()]
示例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()]
示例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')]
示例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()]
示例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:]
示例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)