I made the 0.mp3, 1.mp3, 2.mp3 ... using https://text-to-speech-demo.ng.bluemix.net/
I don't know how I can send you a zip file containing the mp3 audio files. It is about 450 KB in size.
Wav audio files from the Make It talk example sound much better than the mp3 files I created!
You may want to make your own equivalent mp3 audio files.
Here's my mp3 example:
Code: Select all
# see-say-math-tables-mp3.py
# Uses mp3 audio files
# Based wav version say-temp.py by Mike Barela
# for Adafruit Industries, MIT License
import time
import board
import microcontroller
import analogio
import displayio
import terminalio
import audiomp3
from time import sleep
from digitalio import DigitalInOut, Direction, Pull
from adafruit_display_text import label
# from adafruit_bitmap_font import bitmap_font
from adafruit_gizmo import tft_gizmo
try:
from audiocore import WaveFile
except ImportError:
from audioio import WaveFile
try:
from audioio import AudioOut
except ImportError:
try:
from audiopwmio import PWMAudioOut as AudioOut
except ImportError:
pass # not always supported by every board!
display = tft_gizmo.TFT_Gizmo()
font = terminalio.FONT
text_group = displayio.Group(max_size=15, scale=2, x=0, y=0)
space_15 = " "
# Create the text labels
text_area1 = label.Label(font, text=space_15, color=0x00FF00)
# append the labels to a group
text_group.append(text_area1)
display.show(text_group)
maxnum = 10
step = 1
D1 = board.BUTTON_A
D2 = board.BUTTON_B
# Button A setup (Addition)
button_a = DigitalInOut(D1)
button_a.direction = Direction.INPUT
button_a.pull = Pull.DOWN
# Button B setup (Multiplication)
button_b = DigitalInOut(D2)
button_b.direction = Direction.INPUT
button_b.pull = Pull.DOWN
# Audio playback object and helper to play a full file
aout = AudioOut(board.SPEAKER)
# Play a mp3 file
def play_file(mp3file):
mp3file = "/numbers_mp3/" + mp3file
print("Playing", mp3file)
with open(mp3file, "rb") as data:
mp3 = audiomp3.MP3Decoder(data)
aout.play(mp3)
while aout.playing:
pass
# Function should take an integer -299 to 299 and say it
# Assumes mp3 files are available for the numbers
def say_num(n):
if n < 0:
play_file("negative.mp3")
n = - n
if n >= 200:
play_file("200.mp3")
n = n - 200
elif n >= 100:
play_file("100.mp3")
n = n - 100
if (n >= 0 and n < 20) or n % 10 == 0:
play_file(str(n) + ".mp3")
else:
play_file(str(n // 10) + "0.mp3")
n = n - ((n // 10) * 10)
play_file(str(n) + ".mp3")
while True:
if button_a.value:
# play_file("addition.mp3")
for n in range(1, maxnum + 1, step):
# Set the locations
text_area1.x = 20
text_area1.y = 0
for m in range(0, maxnum + 1, step):
text_area1.y += 10
sum = n + m
text_area1.text = "%2.0f" % m + " + " + "%2.0f" % n + " = " + "%2.0f" % sum
say_num(m)
play_file("plus.mp3")
say_num(n)
play_file("is.mp3")
say_num(sum)
time.sleep(0.5)
if button_b.value:
# play_file("Multiplication.mp3")
for n in range(1, maxnum + 1, step):
# Set the locations
text_area1.x = 20
text_area1.y = 0
for m in range(0, maxnum + 1, step):
text_area1.y += 10
prod = n * m
text_area1.text = "%2.0f" % m + " x " + "%2.0f" % n + " = " + "%2.0f" % prod
say_num(m)
play_file("times.mp3")
say_num(n)
play_file("is.mp3")
say_num(prod)
time.sleep(0.5)
time.sleep(0.01)
text_area1.text = " "
Code: Select all
# say-number-mp3.py
# Based wav version say-temp.py by Mike Barela
# for Adafruit Industries, MIT License
import time
import board
import audiomp3
from digitalio import DigitalInOut, Direction, Pull
try:
from audiocore import WaveFile
except ImportError:
from audioio import WaveFile
try:
from audioio import AudioOut
except ImportError:
try:
from audiopwmio import PWMAudioOut as AudioOut
except ImportError:
pass # not always supported by every board!
maxnum = 10
countby = 2
D1 = board.BUTTON_A
D2 = board.BUTTON_B
# Button A setup (CountDown)
button_a = DigitalInOut(D1)
button_a.direction = Direction.INPUT
button_a.pull = Pull.DOWN
# Button B setup (CountUp)
button_b = DigitalInOut(D2)
button_b.direction = Direction.INPUT
button_b.pull = Pull.DOWN
# Audio playback object and helper to play a full file
aout = AudioOut(board.SPEAKER)
# Play a mp3 file
def play_file(mp3file):
mp3file = "/numbers_mp3/" + mp3file
print("Playing", mp3file)
with open(mp3file, "rb") as data:
mp3 = audiomp3.MP3Decoder(data)
aout.play(mp3)
while aout.playing:
pass
# Function should take an integer -299 to 299 and say it
# Assumes mp3 files are available for the numbers
def say_num(n):
if n < 0:
play_file("negative.mp3")
n = - n
if n >= 200:
play_file("200.mp3")
n = n - 200
elif n >= 100:
play_file("100.mp3")
n = n - 100
if (n >= 0 and n < 20) or n % 10 == 0:
play_file(str(n) + ".mp3")
else:
play_file(str(n // 10) + "0.mp3")
n = n - ((n // 10) * 10)
play_file(str(n) + ".mp3")
while True:
if button_a.value:
play_file("CountDownBegin.mp3")
for n in range(maxnum, -1, -countby):
say_num(n)
play_file("blastoff.mp3")
if button_b.value:
play_file("CountUpBegin.mp3")
for n in range(0, maxnum + 1, countby):
say_num(n)
play_file("MaximumCount.mp3")
time.sleep(0.01)