Setting up voice with docker compose: "Failed to connect"

speech-to-phrase currently fails with the error “Failed to connect” when I select Settings > Devices & services > Devices tab > Add Device > search Wyoming Protocol and add host 192.168.0.13, port 10300.

I just got Home Assistant Voice Preview Edition. I have Home Assistant running in a Docker container, so the official documentation doesn’t give step-by-step instructions for local voice processing. I added Wyoming Protocol for Piper without issue.

Any hints?

Speech-to-phrase compose.yml

version: '3.8'
services:
  speech-to-phrase:
    container_name: speech-to-phrase
    image: "rhasspy/wyoming-speech-to-phrase"
    ports:
      - "10300:10300"
    volumes:
      - ./models:/models
      - ./train:/train
    command:
      --hass-websocket-uri 'ws://192.168.0.13:8123/api/websocket'
      --hass-token 'REMOVED_FOR_PRIVACY'
      --retrain-on-start
    restart: unless-stopped

sudo docker-compose up -d gives

Creating network “speech-to-phrase_default” with the default driver
Creating speech-to-phrase … done

Piper compose.yml

version: "3"
services:
  wyoming-piper:
    image: rhasspy/wyoming-piper
    ports:
      - "10200:10200"
    volumes:
      - "./piper/data:/data"
    command: [ "--voice", "en-gb-southern_english_female-low" ]
    restart: unless-stopped

sudo docker-copmpose up -d gives

Creating network “piper_default” with the default driver
Creating piper_wyoming-piper_1 … done

Adding Piper via the Wyoming Protocol (Settings > Devices & services > Devices tab > Add Device > search Wyoming Protocol and add host 192.168.0.13, port 10200) worked without issue.

i’m also starting with similar setup. However my compose uses rhasspy/wyoming-whisper, not sure yet what the differences are between yours selected and this one, with me integration setup was no issue.
Now i see differences, i might switch to speech to phrase btw :slight_smile:

services:
  whisper:
    container_name: whisper
    image: rhasspy/wyoming-whisper
    command: --model tiny-int8 --language nl
    volumes:
      - ./wyoming-whisper:/data
    environment:
      - TZ=Europe/Amsterdam
    ports:
      - "10300:10300"
    restart: unless-stopped
  
  # TTS: Piper (Spreken)
  piper:
    container_name: piper
    image: rhasspy/wyoming-piper
    command: --voice nl_NL-pim-medium
    volumes:
      - ./wyoming-piper:/data
    environment:
      - TZ=Europe/Amsterdam
    ports:
      - "10200:10200"
    restart: unless-stopped

I use hostname to connect containers. so containerhostname:10300
I dont think this is your issue but just a quick sidenote.

I always suggest checking container log first.
Are you sure Speech2phrase container is running properly. First time I launch S2P it was running but failed training so could not allow connections from HA.

compose file look OK.

Portainer make log viewing of containers easy as well as easy command line when needed.

EDIT: i dont use ’ ’ with my api key. that may matter

Thanks for pointing me to the container logs for speech-to-phrase. (I didn’t realize those were a thing. :slight_smile: ) It says, “Connection timeout to host ws://192.168.0.13:8123/api/websocket” Visiting “http://192.168.0.13:8123” in the browser loads without issue and I can connect via websocket using the browser dev tools.

I tried removing the single quotes from the API key and reran docker-compose down and up. It gave the same error in the logs. Below is the last portion of the logs from Docker.

Not sure what to try next.

docker logs --since 2m speech-to-phrase
...
TimeoutError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/usr/src/.venv/lib/python3.11/site-packages/speech_to_phrase/__main__.py", line 191, in <module>
    asyncio.run(main())
  File "/usr/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/usr/src/.venv/lib/python3.11/site-packages/speech_to_phrase/__main__.py", line 96, in main
    await _retrain_once(state, force_retrain=True)
  File "/usr/src/.venv/lib/python3.11/site-packages/speech_to_phrase/__main__.py", line 131, in _retrain_once
    hass_info = await get_hass_info(
                ^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/.venv/lib/python3.11/site-packages/speech_to_phrase/hass_api.py", line 249, in get_hass_info
    async with session.ws_connect(uri, max_msg_size=0) as websocket:
  File "/usr/src/.venv/lib/python3.11/site-packages/aiohttp/client.py", line 1482, in __aenter__
    self._resp: _RetType = await self._coro
                           ^^^^^^^^^^^^^^^^
  File "/usr/src/.venv/lib/python3.11/site-packages/aiohttp/client.py", line 1061, in _ws_connect
    resp = await self.request(
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/src/.venv/lib/python3.11/site-packages/aiohttp/client.py", line 770, in _request
    resp = await handler(req)
           ^^^^^^^^^^^^^^^^^^
  File "/usr/src/.venv/lib/python3.11/site-packages/aiohttp/client.py", line 729, in _connect_and_send_request
    raise ConnectionTimeoutError(
aiohttp.client_exceptions.ConnectionTimeoutError: Connection timeout to host ws://192.168.0.13:8123/api/websocket

Is that ip within docker network or your LAN?

For whatever reason it connect connect to HA.
It could be network issue or could be hass token

192.168.0.13 is the LAN IP for the machine that host all my docker containers (Home Assistant, Wyoming Piper, and Wyoming Speech to Phrase)

Can you put them on same docker network and test with docker ip or container host name?

I ended up switching to whisper and it worked without issue.

1 Like