Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--tts-stop-command runs at beginning of tts, not end #92

Closed
jerblack opened this issue Jan 27, 2024 · 9 comments · Fixed by #94
Closed

--tts-stop-command runs at beginning of tts, not end #92

jerblack opened this issue Jan 27, 2024 · 9 comments · Fixed by #94

Comments

@jerblack
Copy link

jerblack commented Jan 27, 2024

The --tts-stop-command implies that it won't run until the TTS response from the server is returned and fully spoken, but that is not what I am seeing. I have a duck script that runs from --detection-command that mutes two Snapcast clients I have in the same room on different Pis, and an unduck script that runs on --tts-stop-command and --error-command. What I am seeing is that when detection starts, the audio on the other snapcast clients properly mute, but as soon as it's done listening to me, it immediately calls the unduck script and unmutes the snapcast clients, and then begins speaking so the TTS reponse is playing while the music is also playing.

Shouldn't --tts-stop-command only run after the response is finished playing?

Here's my ExecStart= from the wyoming-satellite.service file.

ExecStart=/usr/bin/python3 -m wyoming_satellite --name 'Living Room' \
            --uri tcp://0.0.0.0:10700 \
            --mic-command 'parecord --property=media.role=phone --rate=16000 --channels=1 --format=s16le --raw' \
            --snd-command 'paplay --property=media.role=announce --rate=44100 --channels=1 --format=s16le --raw' \
            --snd-command-rate 44100 \
            --awake-wav /home/jeremy/speech_wav/on.wav \
            --done-wav /home/jeremy/speech_wav/sleep.wav \
            --detection-command '/usr/local/bin/duck' \
            --tts-stop-command '/usr/local/bin/unduck' \
            --error-command '/usr/local/bin/unduck' \
            --mic-noise-suppression 2 \
            --mic-auto-gain 0 \
            --mic-volume-multiplier 1.0 \
            --wake-uri tcp://127.0.0.1:10400 \
            --wake-word-name jarvis \
            --event-uri tcp://127.0.0.1:10500

and my duck and unduck acripts.

# /usr/local/bin/duck
#!/bin/bash
curl -X POST http://spotify.home:1780/jsonrpc -d '{"id":"8","jsonrpc":"2.0","method":"Client.SetVolume","params":{"id":"living_room","volume":{"muted":false,"percent":0}}}' &
curl -X POST http://spotify.home:1780/jsonrpc -d '{"id":"8","jsonrpc":"2.0","method":"Client.SetVolume","params":{"id":"desktop","volume":{"muted":false,"percent":0}}}' &
# /usr/local/bin/unduck
#!/bin/bash
curl -X POST http://spotify.home:1780/jsonrpc -d '{"id":"8","jsonrpc":"2.0","method":"Client.SetVolume","params":{"id":"living_room","volume":{"muted":false,"percent":100}}}' &
curl -X POST http://spotify.home:1780/jsonrpc -d '{"id":"8","jsonrpc":"2.0","method":"Client.SetVolume","params":{"id":"desktop","volume":{"muted":false,"percent":100}}}' &
@llluis
Copy link
Contributor

llluis commented Jan 29, 2024

Shouldn't --tts-stop-command only run after the response is finished playing?

Actually, it is fired when response finished being sent from server, not necessarily being played.
I flagged this a while ago (see #63) and a modification was done to fire a new event Played. However, it was not exposed to a command line. I just submitted a PR to expose it. Once merged, you could replace --tts-stop-command by --played-command and you will have the expected behaviour.

I have the exact same use case as you and that's why I implemented it. :)

@danielk117
Copy link

I've played around with the new tts-played-command event. It seems, it is triggered after every playback, not only the tts one. It is also triggered when using awake and done wav.

DEBUG:root:Wake word detected
DEBUG:root:Running ['/data/satellite/commands/detection']
DEBUG:root:Muting microphone for 0.5381859410430839 second(s)
DEBUG:root:Connected to snd service
Playing raw data 'stdin' : Signed 16 bit Little Endian, Rate 22050 Hz, Mono # awake wav
DEBUG:root:Unmuted microphone
DEBUG:root:Running ['/data/satellite/commands/tts_played'] # wrong trigger
DEBUG:root:Running ['/data/satellite/commands/stt_stop']
DEBUG:root:Event(type='transcript', data={'text': 'test'}, payload=None)
DEBUG:root:Running ['/data/satellite/commands/transcript']
INFO:root:Streaming audio
DEBUG:root:Connected to snd service
Playing raw data 'stdin' : Signed 16 bit Little Endian, Rate 22050 Hz, Mono # tts wav
DEBUG:root:Event(type='synthesize', data={'text': 'test', 'voice': {'name': 'de_DE-thorsten-low'}}, payload=None)
DEBUG:root:Running ['/data/satellite/commands/tts_start']
DEBUG:root:Running ['/data/satellite/commands/detect']
DEBUG:root:Running ['/data/satellite/commands/tts_played'] # wrong trigger
DEBUG:root:Connected to snd service
Playing raw data 'stdin' : Signed 16 bit Little Endian, Rate 22050 Hz, Mono # done wav
DEBUG:root:Running ['/data/satellite/commands/tts_played']

@llluis
Copy link
Contributor

llluis commented Feb 5, 2024

I've played around with the new tts-played-command event. It seems, it is triggered after every playback, not only the tts one. It is also triggered when using awake and done wav.

I'm looking at it. Can you please post your --snd-command ?

@danielk117
Copy link

My --snd-command is aplay -D notify -r 22050 -c 1 -f S16_LE -t raw.

@llluis
Copy link
Contributor

llluis commented Feb 8, 2024

Yeah, I confirm the bug... Trying to find a solution without modifying the wyoming events...

@llluis
Copy link
Contributor

llluis commented Feb 8, 2024

I submitted the correction, shall be merged soon by synesthesiam. The played event won't be fired anymore for the wav plays. Thanks for pointing this out.

@danielk117
Copy link

Great, I will test and report when it is puplished. Thanks you!

@Chreece
Copy link

Chreece commented Jun 25, 2024

I'm having the same problem, every time a wav played on the satellite system the tts-played-command is fired.
Running on docker, just pulled the git to confirm I'm on the latest version

config:

  wyoming-satellite:
    container_name: satellite
    build:
      context: ~/voice-assistant/wyoming-satellite
      dockerfile: ../Dockerfile
    restart: unless-stopped
    volumes:
      - "/etc/asound.conf:/etc/asound.conf"
      - "/etc/localtime:/etc/localtime:ro"
    ports:
      - "10700:10700"
#      - "6600:6600/tcp"   # Map MPD TCP port to the container
#      - "6601:6601/udp"   # Map MPD TCP port to the container
    privileged: true
    ipc: host
    devices:
      - "/dev/snd:/dev/snd"
    command:
      - "--name"
      - "Gästezimmer Assistant"
      - "--mic-command"
      - "arecord --device='plughw:CARD=Microphone,DEV=0' -r 16000 -c 1 -f S16_LE -t raw"
#      - "--snd-uri"
#      - "tcp://192.168.178.57:6601"
      - "--snd-command"
      - "aplay --device='plughw:CARD=Headphones,DEV=0' -r 22050 -c 1 -f S16_LE -t raw"
      - "--debug"
      - "--awake-wav"
      - "sounds/awake.wav"
      - "--done-wav"
      - "sounds/done.wav"
      - "--wake-uri"
      - "tcp://wyoming-openwakeword:10400"
      - "--wake-word-name"
      - "ok_nabu"
      - "--tts-start-command"
      - "curl -d '{\"client\":\"Gästezimmer\",\"tts\":\"started\"}' -H \"Authorization: Bearer TOKEN http://ip:port/api/events/voice-assistant"

      - "--tts-played-command"
      - "curl -d '{\"client\":\"Gästezimmer\",\"tts\":\"stopped\"}' -H \"Authorization: Bearer TOKEN http://ip:port/api/events/voice-assistant"

logs:


satellite     | DEBUG:root:Detection(name='ok_nabu_v0.1', timestamp=2942153947455, speaker=None)
satellite     | DEBUG:root:Streaming audio
satellite     | DEBUG:root:Event(type='run-pipeline', data={'start_stage': 'asr', 'end_stage': 'tts', 'restart_on_end': False, 'snd_format': {'rate': 22050, 'width': 2, 'channels': 1}}, payload=None)
satellite     | DEBUG:root:Muting microphone for 0.8995918367346939 second(s)
satellite     | DEBUG:root:Connected to snd service
satellite     | Playing raw data 'stdin' : Signed 16 bit Little Endian, Rate 22050 Hz, Mono
satellite     | DEBUG:root:Running ['curl', '-d', '{"client":"Gästezimmer","tts":"stopped"}', '-H', 'Authorization: Bearer TOKEN', 'http://ip:port/api/events/voice-assistant']
satellite     |   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
satellite     |                                  Dload  Upload   Total   Spent    Left  Speed
100    83  100    42  100    41   3049   2977 --:--:-- --:--:-- --:--:--  6384
satellite     | DEBUG:root:Unmuted microphone
satellite     | DEBUG:root:Event(type='transcript', data={'text': ' Πληροφορίες και ρουπ.'}, payload=None)
satellite     | INFO:root:Waiting for wake word
satellite     | DEBUG:root:Connected to snd service
satellite     | Playing raw data 'stdin' : Signed 16 bit Little Endian, Rate 22050 Hz, Mono
satellite     | DEBUG:root:Event(type='synthesize', data={'text': 'Συγγνώμη, δεν μπόρεσα να το καταλάβω αυτό', 'voice': {'language': 'el'}}, payload=None)
satellite     | DEBUG:root:Running ['curl', '-d', '{"client":"Gästezimmer","tts":"started"}', '-H', 'Authorization: Bearer TOKEN', 'http://ip:port/api/events/voice-assistant']
satellite     |   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
satellite     |                                  Dload  Upload   Total   Spent    Left  Speed
100    83  100    42  100    41   1342   1310 --:--:-- --:--:-- --:--:--  2677
satellite     | DEBUG:root:Running ['curl', '-d', '{"client":"Gästezimmer","tts":"stopped"}', '-H', 'Authorization: Bearer TOKEN', 'http://ip:port/api/events/voice-assistant']'http://192.168.178.57:8123/api/events/voice-assistant']
satellite     |   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
satellite     |                                  Dload  Upload   Total   Spent    Left  Speed
100    83  100    42  100    41   1098   1072 --:--:-- --:--:-- --:--:--  2184
satellite     | DEBUG:root:Connected to snd service
satellite     | Playing raw data 'stdin' : Signed 16 bit Little Endian, Rate 22050 Hz, Mono
satellite     | DEBUG:root:Running ['curl', '-d', '{"client":"Gästezimmer","tts":"stopped"}', '-H', 'Authorization: Bearer TOKEN', 'http://ip:port/api/events/voice-assistant']
satellite     |   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
satellite     |                                  Dload  Upload   Total   Spent    Left  Speed
100    83  100    42  100    41   1536   1500 --:--:-- --:--:-- --:--:--  3074

@Chreece
Copy link

Chreece commented Jun 25, 2024

ok this fixes it:
#100

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants