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