本帖最后由 猪百岁 于 2021-4-21 17:03 编辑
audio(音频) 的使用
详细 API 参考:audio API
import audio
player = audio.Audio(path = "/sd/6.wav")
from Maix import I2S
# init i2s(i2s0)
wav_dev = I2S(I2S.DEVICE_0)
# config i2s according to audio info
wav_dev.channel_config(wav_dev.CHANNEL_1, I2S.TRANSMITTER,resolution = I2S.RESOLUTION_16_BIT ,cycles = I2S.SCLK_CYCLES_32, align_mode = I2S.RIGHT_JUSTIFYING_MODE)
# read audio info
wav_info = player.play_process(wav_dev)
print("wav file head information: ", wav_info)
sample_rate = wav_info[1]
wav_dev.set_sample_rate(sample_rate)
# loop to play audio
while True:
ret = player.play()
if ret == None:
print("format error")
break
elif ret==0:
print("end")
break
player.finish()
测试音频地址:6.wav
|