Sounds and Speech: There is a train set described on web.ncf.ca/fx829 with an early video of it running. This is controlled from an old telephone dial and as the engines move there are sensors under the track to locate their position. These and user commands trigger both sounds and speech out of four speakers. I use a relay to select one of two audio amplifiers and the audio channel to select which speaker.
Engine sounds are produced by system calls to "aplay". In c-code this is system("aplay DDL.wav -q"). In this case DDL.wav is just a short audio file producing sounds for Diesel Departing Left (channel) speaker. It could just as easily be a recording saying "Jam on toast please". If you have aplay loaded and a wav file available you can test this from the command line.
For train arrival announcements I use system calls to espeak with a text string I built up using sprintf(). i.e. system("espeak txt") where txt was a string. Here is my c-code to say "Ambulance, Fire or Police" in English (northern uk accent) or French. Note how the file from espeak is passed to aplay. This is likely much easier in Python but it's not a language I use and ditto re the command line.
if (fEnglish) sprintf(sEmerg, "espeak -ven-uk-north -a50 -p10 -s150 --stdout"
" \" Am bulance, Fire, or, Police \" 2>/dev/null | aplay -q");
else sprintf(sEmerg, "espeak -vfr -a50 -p10 -s150 --stdout \" Ambulance, "
"pompiers, ou, la, police \" 2>/dev/null | aplay -q");
Also notice how the word Ambulance is broken up, and the additional commas, to make the output easier to understand. I don't know French so I had a neighbour come over with the translation and then to listen to the output. There is a switch on the control panel to select English/French.
For the station announcements I use the string "the train arriving on platform on is the 12 27 from Arnprior, stopping at ..." To get real time in there I added an i2c DS1337 real time clock which is used to set the system clock which I could then read and build up the text e.g. "12 27"
You are welcome to both code and circuits if they are any use to you. I had meant to put them up on the web site but I don't see them there so it was just another job on my to-do list!