audiomixer –支持音频混合¶
在这些板上可用
- 
class audiomixer.Mixer(voice_count: int = 2, buffer_size: int = 1024, channel_count: int = 2, bits_per_sample: int = 16, samples_signed: bool = True, sample_rate: int = 8000)¶
- 将一个或多个音频样本混合成一个样本。 - 创建一个 Mixer 对象,该对象可以以相同的采样率混合多个通道。使用混音器的 - audiomixer.MixerVoice对象访问和控制样本。- 参数
 - 从闪存播放波形文件: - import board import audioio import audiocore import audiomixer import digitalio a = audioio.AudioOut(board.A0) music = audiocore.WaveFile(open("cplay-5.1-16bit-16khz.wav", "rb")) drum = audiocore.WaveFile(open("drum.wav", "rb")) mixer = audiomixer.Mixer(voice_count=2, sample_rate=16000, channel_count=1, bits_per_sample=16, samples_signed=True) print("playing") # Have AudioOut play our Mixer source a.play(mixer) # Play the first sample voice mixer.voice[0].play(music) while mixer.playing: # Play the second sample voice mixer.voice[1].play(drum) time.sleep(1) print("stopped") - 
playing:bool¶
- 输出任何语音时为真。(只读) 
 - 
sample_rate:int¶
- 32 位值,指示以赫兹(每秒周期数)为单位播放样本的速度。 
 - 
voice:Tuple[MixerVoice, Ellipsis]¶
- 混合器 - audiomixer.MixerVoice对象的元组。- >>> mixer.voice (<MixerVoice>,) 
 - 
__exit__(self) → None¶
- 退出上下文时自动取消初始化硬件。有关更多信息,请参阅 Lifetime 和 ContextManagers 。 
 - 
play(self, sample: _typing.AudioSample, *, voice: int = 0, loop: bool = False) → None¶
- 当 loop=False 时播放一次样本,当 loop=True 时连续播放。不阻塞。使用 - playing以块。- 样品必须是 - audiocore.WaveFile,- audiocore.RawSample,- audiomixer.Mixer或- audiomp3.MP3Decoder。- 样本必须与构造函数中给出的 Mixer 编码设置相匹配。 
 
- 
class audiomixer.MixerVoice¶
- 与 Mixer 一起使用的语音对象 - 用于访问和控制样本 - audiomixer.Mixer。- 由 - audiomixer.Mixer创建的 MixerVoice 实例对象。- 
level:float¶
- 声音的音量级别,以 0 到 1 之间的浮点数表示。 
 - 
playing:bool¶
- 输出此语音时为真。(只读) 
 - 
play(self, sample: _typing.AudioSample, *, loop: bool = False) → None¶
- 在 时播放一次样本,在 时 - loop=False, 连续播放- loop=True。不阻塞。使用- playing以块。- 样品必须是 - audiocore.WaveFile,- audiocore.RawSample,- audiomixer.Mixer或- audiomp3.MP3Decoder。- 样本必须与 - audiomixer.Mixer构造函数中给出的 的编码设置相匹配。
 
-