pdf-icon

UIFlow Guide

UIFlow 1.0 Blockly

Event

Unit

UIFlow 1.0 Project

Spk2

案例程序

每隔一秒播放一个语调持续一秒,并调节音量到6

from m5stack import *
from m5ui import *
from uiflow import *
import time
import hat

setScreenColor(0x111111)

hat_spk2_0 = hat.get(hat.SPEAKER_I2S)

while True:
  hat_spk2_0.playTone(220, 1, volume=6)
  wait(1)
  hat_spk2_0.playTone(247, 1, volume=6)
  wait(1)
  hat_spk2_0.playTone(131, 1, volume=6)
  wait(1)
  wait_ms(2)

功能说明

hat_spk2_0.playCloudWAV('', volume=0)
  • 通过提供的URL播放云端的WAV音频文件,并可以设置音量
hat_spk2_0.playTone(220, 1, volume=0)
  • 播放指定的音调(如 Low A),持续1个节拍,并可以调整音量
hat_spk2_0.playTone(220, 1, volume=0)
  • 播放指定频率(如 220 Hz)的音调,持续1个节拍,音量也可以调整
/
  • 从本地选择一个WAV音频文件进行播放,并设置音量
hat_spk2_0.playWAV('', rate=44100, data_format=hat_spk2_0.F16B, channel=hat_spk2_0.CHN_LR, volume=0)
  • 通过设置采样率、数据格式、声道和音量,播放指定的WAV文件
On This Page