
Piarm, Release 1.0
cd
/
home
/
pi
/
piarm
/
examples
sudo python3 sound_effect
.
py
After the code is run, you will find that PiArm first plays the sound effect in the sound function, and then plays the
background music. When the background music is played, the [tts] function is run for timing, and the countdown
voice broadcast will be performed after 30 seconds.
Code
from
robot_hat
import
Music,TTS
from
time
import
sleep
m
=
Music()
t
=
TTS()
def
sound
():
song
=
'./sounds/sign.wav'
m
.
music_set_volume(
40
)
m
.
sound_play(song)
def
background_music
():
music
=
'./musics/sports-Ahjay_Stelino.mp3'
m
.
music_set_volume(
50
)
m
.
background_music(music)
def
tts
():
t
.
say(
"timing begins"
)
sleep(
1
)
t
.
say(
"three"
)
sleep(
1
)
t
.
say(
"two"
)
sleep(
1
)
t
.
say(
"one"
)
sleep(
1
)
t
.
say(
"Stop music"
)
sleep(
1
)
if
__name__
==
"__main__"
:
background_music()
sleep(
10
)
#sound()
#tts()
while
True
:
#background_music()
sound()
tts()
How it works?
The code is simple, it creates 3 functions
sound()
,
background()
and
tts()
, and then calls them separately to
make PiArm play music and speak.
def
sound
():
song
=
'./sounds/sign.wav'
m
.
music_set_volume(
40
)
m
.
sound_play(song)
Play the sound effect
. /sounds/sign.wav
at 40% volume.
4.3. Sound Effects
113
Summary of Contents for PiArm
Page 1: ...Piarm Release 1 0 www sunfounder com Mar 31 2022 ...
Page 2: ......
Page 4: ...ii ...
Page 6: ...Piarm Release 1 0 2 CONTENTS ...
Page 8: ...Piarm Release 1 0 4 Chapter 1 Component List and Assembly Instructions ...
Page 48: ...Piarm Release 1 0 44 Chapter 3 Play with Ezblock ...
Page 91: ...Piarm Release 1 0 3 9 GAME Iron Collection 87 ...
Page 92: ...Piarm Release 1 0 88 Chapter 3 Play with Ezblock ...
Page 99: ...Piarm Release 1 0 Step 7 Click the WRITE button 4 1 Quick Guide on Python 95 ...
Page 148: ...Piarm Release 1 0 Yes then Ok Finish 144 Chapter 5 Appendix ...
Page 152: ...Piarm Release 1 0 Step 4 Double click the connection just created 148 Chapter 5 Appendix ...
Page 160: ...Piarm Release 1 0 156 Chapter 5 Appendix ...