An in-memory sound sample
RawSample(buffer, *, channel_count=1, sample_rate=8000)¶
Create a RawSample based on the given buffer of signed values. If channel_count is more than 1 then each channel’s samples should alternate. In other words, for a two channel buffer, the first sample will be for channel 1, the second sample will be for channel two, the third for channel 1 and so on.
Simple 8ksps 440 Hz sin wave:
import audiocore import audioio import board import array import time import math # Generate one period of sine wav. length = 8000 // 440 sine_wave = array.array("h",  * length) for i in range(length): sine_wave[i] = int(math.sin(math.pi * 2 * i / 18) * (2 ** 15)) dac = audioio.AudioOut(board.SPEAKER) sine_wave = audiocore.RawSample(sine_wave) dac.play(sine_wave, loop=True) time.sleep(1) dac.stop()
Deinitialises the AudioOut and releases any hardware resources for reuse.
No-op used by Context Managers.
Automatically deinitializes the hardware when exiting a context. See Lifetime and ContextManagers for more info.
32 bit value that dictates how quickly samples are played in Hertz (cycles per second). When the sample is looped, this can change the pitch output without changing the underlying sample. This will not change the sample rate of any active playback. Call
playagain to change it.