pdf-icon

Speaker

Speaker Frequency Setting:
Since the hearing range of the average person in the 20~20KHz, so when you set the frequency is too low, or too high, it is not heard!

Speaker M5Core

Example

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

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

API

speaker.tone(1800, 200)
  • Setting the playback sound frequency and duration
speaker.setVolume(1)
  • Setting the Playback Volume
    • Volume range: 0-100
speaker.sing(220, 1)
  • Play the specified tone and beat

Speaker M5Core2

Example

  • Control playtone
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)
  • Control playback of local wav files
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)

API

speaker.playTone(554, 1, volume=6)
  • Play the specified tone (frequency) and set the playback volume.
    • Volume range: 0-6
speaker.playWAV("res/ding.wav", volume=6)
  • Play wav files in the local file system, and set the playback volume.
speaker.playWAV('res/ding.wav', rate=44100, data_format=speaker.F16B, channel=speaker.CHN_LR, volume=6)
  • Play the wav file in the local file system res/filename.wav or SD card /sd/filename.wav, and specify the sample rate and audio data format and channel at the same time.
speaker.playWAV("res/ding.wav", volume=0)
  • Provide an interface to upload wav files to the device in online programming mode, click the + sign to upload operation。
speaker.playCloudWAV('https://xxxxx.wav', volume=6)
  • Fill in the URL to play the wav file in the cloud
Note:
Only WAV type files are supported with a maximum size of 500KB, to prevent the file from being too large, it is recommended to use 16000 sampling frequency, 16 Bit WAV files.
On This Page