pdf-icon

UIFlow Guide

UIFlow 1.0 Blockly

Event

Unit

UIFlow 1.0 Project

Speaker

扬声器频率设置:
由于一般人的听力范围在20~20KHz,所以当你将频率设置得过低,或过高时,是听不到它的声音的

Speaker For M5Core

案例程序

from m5stack import *
from m5ui import *
from uiflow import *
setScreenColor(0x222222)

speaker.setVolume(90)
speaker.sing(220, 1)
speaker.tone(1800, 200)

功能说明

speaker.tone(1800, 200)
  • 设置播放声音频率与持续时间
speaker.setVolume(1)
  • 设置播放音量
    • 音量范围: 0-100
speaker.sing(220, 1)
  • 播放指定tone与节拍

Speaker For M5Core2

案例程序

  • 控制播放tone
from m5stack import *
from m5stack_ui import *
from uiflow import *

screen = M5Screen()
screen.clean_screen()
screen.set_screen_bg_color(0xFFFFFF)

speaker.playTone(554, 1, volume=6)
speaker.playTone(554, 1, volume=6)
  • 控制播放本地wav文件
from m5stack import *
from m5stack_ui import *
from uiflow import *
import time

screen = M5Screen()
screen.clean_screen()
screen.set_screen_bg_color(0xFFFFFF)

speaker.playWAV("res/ding.wav", volume=6)
wait(1)
speaker.playWAV('res/ding.wav', rate=44100, data_format=speaker.F16B, channel=speaker.CHN_LR, volume=6)

功能说明

speaker.playTone(554, 1, volume=6)
  • 播放指定tone(频率), 同时设置播放音量大小
    • 音量范围: 0-6
speaker.playWAV("res/ding.wav", volume=6)
  • 播放本机文件系统中的wav文件, 同时设置播放音量大小
speaker.playWAV('res/ding.wav', rate=44100, data_format=speaker.F16B, channel=speaker.CHN_LR, volume=6)
  • 播放本机文件系统res/filename.wav或SD卡/sd/filename.wav中的wav文件,同时指定采样率和音频数据格式和声道
speaker.playWAV("res/ding.wav", volume=0)
  • 在线编程模式下,提供接口上传wav文件至设备, 点击+号进行上传操作。
speaker.playCloudWAV('https://xxxxx.wav', volume=6)
  • 填入URL播放云端wav文件
注意事项:
仅支持WAV类型文件且最大不超过500KB, 为防止文件过大,建议使用16000采样频率,16 Bit WAV文件
On This Page