I am a long time reader, newbie poster on these forums,
Thought I'd share my latest project with you guys, hoping to get some improvement tips and/or feedback.
I was looking into a way to make the Raspberry Pi speak the current time.
Using google's TTS-engine was not an option because it doesn't sound very natural IMO.
So I asked a female friend with a pleasureable voice to record some .wav files.
The files contain the numbers 0 to 60 (all separate files), the words 'Good morning', 'Good afternoon', 'Good evening', 'Good night', 'It is', 'Hours', 'Minutes', 'AM' and 'PM'
The next step was writing a script that converts the time to call the appropriate audio-files.
One thing I noticed along the way was that omxplayer took its time to play each file. So there was a one-second gap between each audio-file.
Combining all audio-files to one big file was a possible solution. Due to the WAV-header in each file it is not possible to just cat out all files to a 'bigfile.wav'
Searching the web for a while, I found a repository called sox, wich does the trick (and much more)
steps taken:
1) sudo apt-get update
2) sudo apt-get install sox
3) copy all wav-files to /home/pi/sounds
4) write a script:
Code: Select all
#!/usr/bin/env python
# Imports
import os
from time import strftime
# Audio
output = '/home/pi/voices/output.wav'
gmorning = '/home/pi/voices/gmorning.wav'
gafternoon = '/home/pi/voices/gafternoon.wav'
gevening = '/home/pi/voices/gevening.wav'
gnight = '/home/pi/voices/gnight.wav'
it_is = '/home/pi/voices/its.wav'
hours = '/home/pi/voices/hour.wav'
minutes = '/home/pi/voices/minutes.wav'
am = '/home/pi/voices/am.wav'
pm = '/home/pi/voices/pm.wav'
# Program starts here
if int(strftime("%H")) >= 5 and int(strftime("%H")) <= 11:
greeting = gmorning
elif int(strftime("%H")) >= 12 and int(strftime("%H")) <= 17:
greeting = gafternoon
elif int(strftime("%H")) >= 18 and int(strftime("%H")) <=23 :
greeting = gevening
elif int(strftime("%H")) <=5 and int(strftime("%H")) >= 0 :
greeting = gnight
hour = int(strftime("%H"))
if hour > 12:
hour = hour - 12
post = pm
elseif hour = 12:
post = pm
else:
post = am
minute = int(strftime("%M"))
u = '/home/pi/voices/'+str(hour)+'.wav'
m = '/home/pi/voices/'+str(minute)+'.wav'
combine = 'sox '+greeting+' '+it_is+' '+u+' '+hours+' '+' '+m+' '+minutes+' '+post+' '+output
os.system(combine)
os.system('omxplayer /home/pi/voices/output.wav > /dev/null')