i am using speach from different apps.
the code is now like this:
def say(self,text,lang):
with tempfile.NamedTemporaryFile(suffix='.mp3', delete=False) as f:
fname = f.name
tts = gTTS(text=text, lang=lang)
tts.save(fname)
self.play(fname)
os.remove(fname)
def play(self,filename):
cmd = ['omxplayer','-o','local',filename]
with tempfile.TemporaryFile() as f:
subprocess.call(cmd, stdout=f, stderr=f)
f.seek(0)
output = f.read()
in different apps i use:
speak = self.get_app("speak")
speak.say(speaktext,"nl")
or like now in the Christmas time every hour:
speaktext = "het is nu " + str(runhour) + " uur."
speak = self.get_app("speak")
speak.say(speaktext,"nl")
musiclist = ["/mnt/music/Groepen/Kerst mp3's/Gene Autry - Frosty the Snowman.mp3",
"/mnt/music/Groepen/Kerst mp3's/Kenny G - White Christmas.mp3",
"/mnt/music/Groepen/Kerst mp3's/Pat Benatar - Please Come Home For Chistmas.mp3",
"/mnt/music/Groepen/Kerst mp3's/Paul McCartney - Pipes Of Peace.mp3",
"/mnt/music/Groepen/Kerst mp3's/Moonglows - Hey Santa Claus.mp3",
"/mnt/music/Groepen/Kerst mp3's/Techno Christmas - Jingle Bells.mp3",
"/mnt/music/Groepen/Kerst mp3's/The Platters - Blue Christmas.mp3",
"/mnt/music/Groepen/Kerst mp3's/Mariah Carey - All I Want For Christmas Is You.mp3",
"/mnt/music/Groepen/Kerst mp3's/Bobby Sherman - I Saw Mommy Kissing Santa Claus.mp3",
"/mnt/music/Groepen/Kerst mp3's/Enya - Silent Night.mp3",
"/mnt/music/Groepen/Kerst mp3's/Louis Armstrong - Christmas in New Orleans.mp3",
"/mnt/music/Groepen/Kerst mp3's/Bill Pinky and the Original Drifters - We Wish You a Merry Christmas.mp3"]
myrandomnumber = random.randrange(0,11,1)
speak.play(musiclist[myrandomnumber])
and as long as i use 1 thread it works like a charm.
as soon as i use more threads i get things spoken/played at the same time.
right now i am trying to get vlc mediaplayer working with hass or in appdaemon.
then i could create a playlist and my problem would also be gone.
but i struggle with vlc. ![:wink: :wink:](https://community.home-assistant.io/images/emoji/twitter/wink.png?v=9)