TTS update

My previous post :slight_smile:

Hi,

My problem was the user running hass-daemon (root) was unable to run audio on soundcard.
So i had to configure pulseaudio to do that

addgroup --system pulse
adduser --system --ingroup pulse --home /var/run/pulse pulse
addgroup --system pulse-access
adduser pulse audio
adduser root pulse-access

if already is fine you need to do that as root
pulseaudio -D --system

now you can test the mp3 generated
cd /tmp/tts
vlc generated.mp3

if it works now you need to execute pulseaudio -D --system at startup.

I modifiy /etc/init.d/hass-daemon with that:
start() {
if [ -f $PID_FILE ] && kill -0 $(cat $PID_FILE) 2> /dev/null; then
echo ‘Service already running’ >&2
return 1
fi
echo ‘Starting service…’ >&2
local CMD="$PRE_EXEC hass $FLAGS $REDIRECT;"
su -c “$CMD” $RUN_AS
echo ‘Service started’ >&2
su -c “pulseaudio -D --system” $RUN_AS
}

it’s so dirty because if i restart hass, pulseaudio -D --system is already active, but it’s not a big deal.

Oh, just realsized that post was you, I hesitated to do it as its a bit dirty, I was thinking someone might get a better way, hahaha, hopefully the future version will fix this issue.

Should never run anything as root… first problem.

Thanx guys, I’ll try VLC + pulseausio…
Just - do I need to install both? I need only something which will work with TTS

Atm I can play mp3s using VLC over the command line, but not with HA (TTS). TTS is working however with my chromecasts. I did install HA using the Hassbian image (https://home-assistant.io/getting-started/installation-raspberry-pi-image/) with user homeassistant.

Should I give homeassistant access to pulseaudio to get it working?

addgroup --system pulse
adduser --system --ingroup pulse --home /var/run/pulse pulse
addgroup --system pulse-access
adduser pulse audio
adduser homeassistant pulse-access

Hi,

Yes my problem was here.
After giving rights to user from pulseaudio everything works fine !

Doesn’t work here… got my VLC broken now, can’t play sounds anymore (only some white noise). Thanks for helping anyway! Some work to do this weekend:)

I had created a custom TTS solution sometime back as the TTS was not available on early releases of HA.

I am using PicoTTS, which is one of the good offline TTS engine I came across so far.

Here is the demo: View Demo

In the demo, the TTS is for the motion detection sensor. (My custom Microwave Radar Sensor using MySensors node)

I’m happy to share the details if anyone interested :slight_smile:

Also see my Grandfather Clock Chime implementation Here

I have tried Pico using this guide but the sound is too muffled or too much bass. Google TTS sounds much clearer and natural. But honestly I prefer something that works offline and independent from a 3rd party provider. Unfortunately, Google TTS is the best option for me right now. Do you have any other suggestion for offline TTS that is comparable to Google?

I had similar issue with sound using Pulse audio. Alsa works fine for me.

Here is some info about PicoTTS if any one interested.

Here is the demo: View Demo

Installing PicoTTS

sudo su
cd /
wget http://incrediblepbx.com/picotts-raspi.tar.gz
tar zxvf picotts-raspi.tar.gz
rm -f picotts-raspi.tar.gz
cd /root
./picotts-install.sh

Testing PicoTTS

pico2wave --wave sample.wav -l en-US "Here is a sample, using the PICO text to speech engine."
aplay sample.wav

Below is the Shell script will take the “Text” as argument to speech conversion

Shell Command File: TTS_Play.sh

#!/bin/bash
pico2wave -w /tmp/omx.wav "$1"
#below line just to play chime sound to gather attention
aplay -Dplughw:CARD=ALSA,DEV=0 /home/homeassistant/.homeassistant/chime.wav
aplay -Dplughw:CARD=ALSA,DEV=0 /tmp/omx.wav

HA Configuration yaml:

input_boolean:
  motion_livingroom_override:
    initial: on

    shell_command:
      ttsplay: '/home/homeassistant/.homeassistant/TTS_Play.sh "Hareesh, You have a visitor!"'

    automation 2:
      - alias: Alert Motion
        trigger:
          platform: state
          entity_id: binary_sensor.motion_sensor_3_1
          from: 'off'
          to: 'on'
        condition:
          - condition: state
            entity_id: input_boolean.motion_livingroom_override
            state: 'on'
        action:
          - service: notify.myhtml5
            data:
              message: 'Motion Deteted at Main Gate!!'
              title: 'Home Assistant Alert'
          - service: shell_command.ttsplay

We can configure the shell_command section with what ever text we need to send to the TTS engine.

1 Like

@hareeshmu that support PT language?

I’m not sure on PT language is available or not. We have to give it a try.

I just found a post on building it from sources.

http://rpihome.blogspot.in/2015/02/installing-pico-tts.html?m=1

It says…pico tts (at least on debian systems) can use just german, english, french
, italian and spanish. Maybe you could try to look at the sources of the software to see if there’s a way to add new voices, but I think it would not be an easy task…

1 Like

I have a base_url that’s behind Let’s Encrypt SSL and the URL is in the config but Sonos is saying connection was lost…

Thoughts?

as an update, going to https://baseurl.example.com/api/tts_proxy/filenameincachefolder.mp3

does work in the browser.

Looks like I didn’t need the base_url. Got it working.

1 Like

I have your example working when I run it as the “pi” user. However when I run it as the “hass” user I get the following error: “X11 connection rejected because of wrong authentication.” looks like I need to grant some permissions to hass. Any suggestions on how I might do this?

Try the chmod 755 or 777 to the specified file. Make sure the user ‘hass’ added to the audio group.

sudo usermod -a -G groupName userName
sudo usermod -a -G audio hass

Got it working now! Thanks guys! Now I am trying to get some random output to TTS, like described here for Alexa. However, when I use

service:  tts.google_say
 data_template:
  entity_id: media_player.speaker
  message:     '{{ ["Hi" , "Bye" ] | random }}'    

TTS always plays the first ‘Hi’, and never the second ‘Bye’. Any ideas?

I have 36.1 All in One Installer. I have applied the permissions above. When I call the google_say service as posted at the top of this page, the file is recorded and saved but no sound comes out of my attached speakers (3.5mm jack). I have applied permissions for audio as described in this post.

I can play sound via command line with either aplay, omxplayer or vlc.

I am getting a play_media not implemented error. I also receive this error if I use picotts_say. I am not sure what else to do here

17-01-28 13:36:13 homeassistant.core: Error doing job: Task exception was never retrieved

Traceback (most recent call last):
File “/usr/lib/python3.4/asyncio/tasks.py”, line 233, in _step
result = coro.throw(exc)
File “/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/core.py”, line 1054, in _event_to_service_call
yield from service_handler.func(service_call)
File “/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/media_player/init.py”, line 364, in async_service_handler
yield from getattr(player, method[‘method’])(**params)
File “/usr/lib/python3.4/asyncio/futures.py”, line 388, in iter
yield self # This tells Task to wait for completion.
File “/usr/lib/python3.4/asyncio/tasks.py”, line 286, in _wakeup
value = future.result()
File “/usr/lib/python3.4/asyncio/futures.py”, line 277, in result
raise self._exception
File “/usr/lib/python3.4/concurrent/futures/thread.py”, line 54, in run
result = self.fn(*self.args, **self.kwargs)
File “/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/media_player/init.py”, line 644, in play_media
raise NotImplementedError()
NotImplementedError

1 Like

I have the same problem with Onkyo media_player. My ownership is updated and permissions …

but, I keep getting this task exception as well!