To play a SEQUENCE of tones, use
The tone_sequence parameter is a list of tuples, where each tuple contains up to three numbers. You should know by now that a tuple is like a list except that a list can be modified and a tuple cannot. The first number is frequency in Hz, the second is duration in milliseconds, and the third is delay in milliseconds between this and the next tone in the sequence.
# so that script can be run from Brickman
from ev3dev.ev3 import * # needed for Sound
# Play a 3000Hz tone for 2 seconds and then wait 0.4 seconds
# before playing the next tone, 800Hz for 1.8 seconds
# Wait for the sequence to finish playing before continuing
Sound.tone([(3000, 2000, 400),(800, 1800, 2000)]).wait()
Play a WAV sound file
To play a WAV sound file, use Sound.play(wav_file) You cannot use mp3 files with the Sound.play command, nor can you use Lego sound files in the RSF or RSO format (but see below).
A good source for free WAV sound files is Wavsource.com. I did have a problem with a WAV file that I downloaded from there though - I got an error message 'underrun' when I ran my script, which suggests that the sound file was damaged. If you get the same message then delete that sound file and try another. A sample wav file 'cat_yowl.wav' from wavsource.com can be downloaded using the link at the bottom of this page. I suggest you make a directory called 'sounds' in your 'robot' directory and use that to contain your WAV files. If you're using VS Code with the EV3 extension as I recommend then this is easy enough. Just make a folder called 'sounds' on your computer and place your WAV files inside that, then open the 'sounds' folder in VS Code and click the 'Send project to device' icon in the header of the EV3 Device browser. This will send a copy of the 'sounds' folder into the 'robot' folder on your EV3. (VS Code needs to be connected to the EV3 of course.) Assuming you have done this and now have the 'cat_yowl.wav' file in a directory called 'sounds' in your 'robot' directory on the EV3 then the following script should work (as long as it is in your robot directory):
from ev3dev.ev3 import *
Sound.beep()
sleep(4)
Sound.play('sounds/cat_yowl.wav')
Notice that the first cat yowl plays before the beep sound but the second plays at the same time as (or even after) the beep because there is no .wait() to make program execution pause until the sound has finished playing before continuing.
I said above that Sound.play() can only play sounds that are in the WAV format and therefore cannot play Lego sounds in the RSF or RSO format. I have made available at the bottom of this page a ZIP file containing all the Lego sounds in WAV format. All the sounds are in the same folder, not separated into different folders as in EV3-G. All the scripts on this site that make use of these sounds assume that you have put them all in a 'sounds' folder inside the 'robot' folder. Therefore the address of the sounds will be /home/robot/sounds/ . This is similar to the way my scripts assume that you have placed all the Lego images in BMP format in a folder called 'pics' in the 'robot' folder. See this page.
Text-to-Speech
Example at the bottom of the combined example below.
Combined Example
An example of a program to demonstrate playing beeps, tones and text-to-speech:
# so that script can be run from Brickman
from time import sleep # needed for sleep
Sound.beep()
sleep(2) # pause for 2 seconds
# Play a SINGLE 2000 Hz tone for 1.5 seconds
# Wait for the tone to finish playing before continuing
# To play a SEQUENCE of tones, use a LIST of TUPLES
# The third argument in each tuple is the delay in ms
# Play a 3000 Hz tone for 2 seconds, then wait 0.4 seconds
# before playing the next tone, 800Hz for 1.8 seconds
# Wait for the sequence to finish playing before continuing
Sound.tone([(3000, 2000, 400),(800, 1800, 2000)]).wait()
# Play a 500 Hz tone for 1 second and then wait 0.4 seconds
# Play the tone three times
Sound.speak('Hello, my name is E V 3!').wait()