Created
June 27, 2022 11:00
-
-
Save comdet/956d53fdc75f5621475071dcdc78aed2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fpioa_manager import * | |
from Maix import I2S, GPIO | |
import audio | |
fm.register(18, fm.fpioa.GPIO1) | |
sound_en=GPIO(GPIO.GPIO1,GPIO.OUT) | |
sound_en.value(1) | |
# register i2s(i2s0) pin | |
fm.register(20,fm.fpioa.I2S0_OUT_D1, force=True) | |
fm.register(21,fm.fpioa.I2S0_SCLK, force=True) | |
fm.register(19,fm.fpioa.I2S0_WS, force=True) | |
# init i2s(i2s0) | |
wav_dev = I2S(I2S.DEVICE_0) | |
# init audio | |
player = audio.Audio(path = "/sd/lungroier.wav") | |
player.volume(80) | |
# read audio info | |
wav_info = player.play_process(wav_dev) | |
print("wav file head information: ", wav_info) | |
# 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) | |
wav_dev.set_sample_rate(wav_info[1]) | |
# loop to play audio | |
while True: | |
ret = player.play() | |
if ret == None: | |
print("format error") | |
break | |
elif ret==0: | |
print("end") | |
break | |
player.finish() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment