From 623346255b35b4808c661c817abf0a4e8e0d4522 Mon Sep 17 00:00:00 2001 From: ChrisB85 Date: Thu, 6 Aug 2026 09:53:17 +0200 Subject: [PATCH 1/7] feat: play a configurable sound when the mic re-opens for follow-ups When Home Assistant asks a follow-up question (continue_conversation) or starts a conversation itself (start_conversation), the satellite re-opened the microphone silently, leaving no cue that it was listening again. Play a sound at that point, configurable via --continue-conversation-sound (CONTINUE_CONVERSATION_SOUND in Docker/systemd). Defaults to the wake word sound; an empty string disables it. --- .env.example | 3 + README.md | 3 +- docker-entrypoint.sh | 5 ++ docs/install_application.md | 2 + linux_voice_assistant/__main__.py | 12 +++ linux_voice_assistant/models.py | 2 + linux_voice_assistant/satellite.py | 21 ++++- tests/test_continue_conversation_sound.py | 102 ++++++++++++++++++++++ 8 files changed, 146 insertions(+), 4 deletions(-) create mode 100644 tests/test_continue_conversation_sound.py diff --git a/.env.example b/.env.example index ee4614fc..c39f337d 100644 --- a/.env.example +++ b/.env.example @@ -108,6 +108,9 @@ LVA_PULSE_COOKIE="/run/user/${LVA_USER_ID}/pulse/cookie" # PROCESSING_SOUND="sounds/processing.wav" # MUTE_SOUND="sounds/mute_switch_on.flac" # UNMUTE_SOUND="sounds/mute_switch_off.flac" +# Sound played when the microphone re-opens for a follow-up question. +# Defaults to WAKEUP_SOUND. Set to "" to disable. +# CONTINUE_CONVERSATION_SOUND="sounds/wake_word_triggered.flac" ### Enable output-only mode (optional): # ENABLE_OUTPUT_ONLY="1" diff --git a/README.md b/README.md index 92346b6a..62ff968f 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ For all other users, we have different installation methods available (Docker, s ```sh usage: __main__.py [-h] [--name NAME] [--audio-input-device AUDIO_INPUT_DEVICE] [--list-input-devices] [--audio-input-block-size AUDIO_INPUT_BLOCK_SIZE] [--audio-output-device AUDIO_OUTPUT_DEVICE] [--music-output-device MUSIC_OUTPUT_DEVICE] [--list-output-devices] [--wake-word-dir WAKE_WORD_DIR] [--mic-auto-gain] [--mic-noise-suppression] [--wake-model WAKE_MODEL] [--stop-model STOP_MODEL] [--download-dir DOWNLOAD_DIR] [--refractory-seconds REFRACTORY_SECONDS] [--wakeup-sound WAKEUP_SOUND] [--timer-finished-sound TIMER_FINISHED_SOUND] [--processing-sound PROCESSING_SOUND] - [--mute-sound MUTE_SOUND] [--unmute-sound UNMUTE_SOUND] [--preferences-file PREFERENCES_FILE] [--host HOST] [--network-interface NETWORK_INTERFACE] [--port PORT] [--enable-thinking-sound] [--listen-during-wake-sound] [--debug] + [--mute-sound MUTE_SOUND] [--unmute-sound UNMUTE_SOUND] [--continue-conversation-sound CONTINUE_CONVERSATION_SOUND] [--preferences-file PREFERENCES_FILE] [--host HOST] [--network-interface NETWORK_INTERFACE] [--port PORT] [--enable-thinking-sound] [--listen-during-wake-sound] [--debug] ``` | Parameter | Description | Default | @@ -103,6 +103,7 @@ usage: __main__.py [-h] [--name NAME] [--audio-input-device AUDIO_INPUT_DEVICE] | `--processing-sound` | Sound played while assistant is processing | `sounds/processing.wav` | | `--mute-sound` | Sound played when muting the assistant | `sounds/mute_switch_on.flac` | | `--unmute-sound` | Sound played when unmuting the assistant | `sounds/mute_switch_off.flac` | +| `--continue-conversation-sound` | Sound played when the mic re-opens for a follow-up question | `--wakeup-sound` (`""` disables) | | `--preferences-file` | Path to preferences JSON file | `preferences.json` | | `--host` | IP-Address for ESPHome server, use 0.0.0.0 for all | Autodetected | | `--network-interface` | Network interface for ESPHome server | Autodetected | diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 1863692a..2a31f869 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -116,6 +116,11 @@ if [ -n "${UNMUTE_SOUND}" ]; then EXTRA_ARGS+=( "--unmute-sound" "$UNMUTE_SOUND" ) fi +# Set-but-empty is meaningful here: it disables the sound. +if [ -n "${CONTINUE_CONVERSATION_SOUND+x}" ]; then + EXTRA_ARGS+=( "--continue-conversation-sound" "$CONTINUE_CONVERSATION_SOUND" ) +fi + if [ -n "${TIMER_MAX_RING_SECONDS}" ]; then EXTRA_ARGS+=( "--timer-max-ring-seconds" "$TIMER_MAX_RING_SECONDS" ) fi diff --git a/docs/install_application.md b/docs/install_application.md index 7bd33213..f986fe04 100644 --- a/docs/install_application.md +++ b/docs/install_application.md @@ -195,6 +195,7 @@ Environment=PREFERENCES_FILE="/home/pi/linux-voice-assistant/preferences.json" # Environment=LISTEN_DURING_WAKE_SOUND="0" # Environment=MUTE_SOUND="sounds/mute_switch_on.flac" # Environment=UNMUTE_SOUND="sounds/mute_switch_off.flac" +# Environment=CONTINUE_CONVERSATION_SOUND="sounds/wake_word_triggered.flac" # Environment=PERIPHERAL_HOST="0.0.0.0" # Environment=PERIPHERAL_PORT="6055" # Environment=PERIPHERAL_VOLUME_STEP="%(default)s" @@ -289,6 +290,7 @@ The following variables can be configured in the `.env` or in the service file: | `LISTEN_DURING_WAKE_SOUND` | false | Set to "1" to start listening immediately after wake word detection, without waiting for the wake sound to finish | | `MUTE_SOUND` | `sounds/mute_switch_on.flac` | Sound file for mute on | | `UNMUTE_SOUND` | `sounds/mute_switch_off.flac` | Sound file for mute off | +| `CONTINUE_CONVERSATION_SOUND` | same as `WAKEUP_SOUND` | Sound file played when the mic re-opens for a follow-up question (set to "" to disable) | | `PERIPHERAL_HOST` | 0.0.0.0 | Host for the peripheral WebSocket API | | `PERIPHERAL_PORT` | 6055 | Port for the peripheral WebSocket API | | `PERIPHERAL_VOLUME_STEP` | %(default)s | Volume change per button press | diff --git a/linux_voice_assistant/__main__.py b/linux_voice_assistant/__main__.py index df8c347c..b78626f2 100644 --- a/linux_voice_assistant/__main__.py +++ b/linux_voice_assistant/__main__.py @@ -148,6 +148,13 @@ async def main() -> None: default=str(_SOUNDS_DIR / "mute_switch_off.flac"), help="Sound to play when unmuting the assistant", ) + parser.add_argument( + "--continue-conversation-sound", + help=( + "Sound to play when the microphone re-opens for a follow-up question " + "(default: same as --wakeup-sound, empty string disables)" + ), + ) parser.add_argument( "--button-double-press-sound", default=str(_SOUNDS_DIR / "button_double_press.flac"), @@ -447,6 +454,11 @@ async def main() -> None: button_double_press_sound=args.button_double_press_sound, button_triple_press_sound=args.button_triple_press_sound, button_long_press_sound=args.button_long_press_sound, + continue_conversation_sound=( + args.wakeup_sound + if args.continue_conversation_sound is None + else args.continue_conversation_sound + ), preferences=preferences, preferences_path=preferences_path, refractory_seconds=args.refractory_seconds, diff --git a/linux_voice_assistant/models.py b/linux_voice_assistant/models.py index 2469d78b..082eefa3 100644 --- a/linux_voice_assistant/models.py +++ b/linux_voice_assistant/models.py @@ -127,6 +127,8 @@ class ServerState: download_dir: Path continue_conversation_delay: float = 0.5 # seconds to wait after TTS before opening mic + # Empty string disables the sound. + continue_conversation_sound: str = "" media_player_entity: "Optional[MediaPlayerEntity]" = None satellite: "Optional[VoiceSatelliteProtocol]" = None connections: "List[VoiceSatelliteProtocol]" = field(default_factory=list) diff --git a/linux_voice_assistant/satellite.py b/linux_voice_assistant/satellite.py index e8670a9a..1e7240b3 100644 --- a/linux_voice_assistant/satellite.py +++ b/linux_voice_assistant/satellite.py @@ -1001,15 +1001,30 @@ def _tts_finished(self) -> None: self._emit(LVAEvent.LISTENING) _LOGGER.debug("Continuing conversation after %.2fs settle delay", self.state.continue_conversation_delay) + def _open_mic() -> None: + self.send_messages([VoiceAssistantRequest(start=True)]) + self._is_streaming_audio = True + _LOGGER.debug("Continued conversation started") + def _start_continued_conversation() -> None: if self.state.muted: _LOGGER.debug("Skipping continued conversation: muted") self._pipeline_active = False self.unduck() return - self.send_messages([VoiceAssistantRequest(start=True)]) - self._is_streaming_audio = True - _LOGGER.debug("Continued conversation started") + + if not self.state.continue_conversation_sound: + _open_mic() + elif self.state.listen_during_wake_sound: + self.state.tts_player.play(self.state.continue_conversation_sound) + _open_mic() + else: + # Same flow as wakeup(): the chime plays first so the mic does + # not stream it back to Home Assistant. + self.state.tts_player.play( + self.state.continue_conversation_sound, + done_callback=_open_mic, + ) threading.Timer(self.state.continue_conversation_delay, _start_continued_conversation).start() else: diff --git a/tests/test_continue_conversation_sound.py b/tests/test_continue_conversation_sound.py new file mode 100644 index 00000000..db19b737 --- /dev/null +++ b/tests/test_continue_conversation_sound.py @@ -0,0 +1,102 @@ +"""Sound feedback when the microphone re-opens for a follow-up question.""" + +from types import SimpleNamespace +from unittest.mock import MagicMock + +from linux_voice_assistant.satellite import VoiceSatelliteProtocol + + +def _satellite( + continue_conversation_sound: str, listen_during_wake_sound: bool = False +) -> VoiceSatelliteProtocol: + satellite = VoiceSatelliteProtocol.__new__(VoiceSatelliteProtocol) + satellite.state = SimpleNamespace( + continue_conversation_sound=continue_conversation_sound, + continue_conversation_delay=0.0, + listen_during_wake_sound=listen_during_wake_sound, + muted=False, + tts_player=MagicMock(), + music_player=MagicMock(), + active_wake_words=set(), + stop_word=SimpleNamespace(id="stop"), + ) + satellite.send_messages = MagicMock() + satellite._emit = MagicMock() + satellite._continue_conversation = True + satellite._is_streaming_audio = False + satellite._pipeline_active = True + return satellite + + +def _run_settle_timer(satellite: VoiceSatelliteProtocol, timer_cls: MagicMock) -> None: + """Invoke the callback that _tts_finished handed to threading.Timer.""" + delay, callback = timer_cls.call_args.args + assert delay == satellite.state.continue_conversation_delay + callback() + + +def test_plays_sound_before_opening_mic(monkeypatch): + satellite = _satellite("wake.flac") + timer_cls = MagicMock() + monkeypatch.setattr("linux_voice_assistant.satellite.threading.Timer", timer_cls) + + satellite._tts_finished() + _run_settle_timer(satellite, timer_cls) + + # Mic must stay closed until the chime finishes, otherwise it streams the chime. + play_call = satellite.state.tts_player.play.call_args + assert play_call.args[0] == "wake.flac" + assert not satellite._is_streaming_audio + + play_call.kwargs["done_callback"]() + assert satellite._is_streaming_audio + + +def test_listen_during_wake_sound_opens_mic_immediately(monkeypatch): + satellite = _satellite("wake.flac", listen_during_wake_sound=True) + timer_cls = MagicMock() + monkeypatch.setattr("linux_voice_assistant.satellite.threading.Timer", timer_cls) + + satellite._tts_finished() + _run_settle_timer(satellite, timer_cls) + + satellite.state.tts_player.play.assert_called_once_with("wake.flac") + assert satellite._is_streaming_audio + + +def test_empty_sound_disables_playback(monkeypatch): + satellite = _satellite("") + timer_cls = MagicMock() + monkeypatch.setattr("linux_voice_assistant.satellite.threading.Timer", timer_cls) + + satellite._tts_finished() + _run_settle_timer(satellite, timer_cls) + + satellite.state.tts_player.play.assert_not_called() + assert satellite._is_streaming_audio + + +def test_muted_skips_sound_and_mic(monkeypatch): + satellite = _satellite("wake.flac") + satellite.state.muted = True + timer_cls = MagicMock() + monkeypatch.setattr("linux_voice_assistant.satellite.threading.Timer", timer_cls) + + satellite._tts_finished() + _run_settle_timer(satellite, timer_cls) + + satellite.state.tts_player.play.assert_not_called() + assert not satellite._is_streaming_audio + + +def test_no_sound_when_conversation_ends(monkeypatch): + satellite = _satellite("wake.flac") + satellite._continue_conversation = False + timer_cls = MagicMock() + monkeypatch.setattr("linux_voice_assistant.satellite.threading.Timer", timer_cls) + + satellite._tts_finished() + + timer_cls.assert_not_called() + satellite.state.tts_player.play.assert_not_called() + satellite.state.music_player.unduck.assert_called_once() From 4744d8cccb3dc8858a71c441e6aaf006e01a1af9 Mon Sep 17 00:00:00 2001 From: ChrisB85 Date: Fri, 25 Sep 2026 13:37:01 +0200 Subject: [PATCH 2/7] Fix lint in continue-conversation sound change --- linux_voice_assistant/__main__.py | 11 ++--------- tests/test_continue_conversation_sound.py | 10 ++++------ 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/linux_voice_assistant/__main__.py b/linux_voice_assistant/__main__.py index b78626f2..ac4f71d2 100644 --- a/linux_voice_assistant/__main__.py +++ b/linux_voice_assistant/__main__.py @@ -150,10 +150,7 @@ async def main() -> None: ) parser.add_argument( "--continue-conversation-sound", - help=( - "Sound to play when the microphone re-opens for a follow-up question " - "(default: same as --wakeup-sound, empty string disables)" - ), + help="Sound to play when the microphone re-opens for a follow-up question (default: same as --wakeup-sound, empty string disables)", ) parser.add_argument( "--button-double-press-sound", @@ -454,11 +451,7 @@ async def main() -> None: button_double_press_sound=args.button_double_press_sound, button_triple_press_sound=args.button_triple_press_sound, button_long_press_sound=args.button_long_press_sound, - continue_conversation_sound=( - args.wakeup_sound - if args.continue_conversation_sound is None - else args.continue_conversation_sound - ), + continue_conversation_sound=(args.wakeup_sound if args.continue_conversation_sound is None else args.continue_conversation_sound), preferences=preferences, preferences_path=preferences_path, refractory_seconds=args.refractory_seconds, diff --git a/tests/test_continue_conversation_sound.py b/tests/test_continue_conversation_sound.py index db19b737..9df36be0 100644 --- a/tests/test_continue_conversation_sound.py +++ b/tests/test_continue_conversation_sound.py @@ -6,11 +6,9 @@ from linux_voice_assistant.satellite import VoiceSatelliteProtocol -def _satellite( - continue_conversation_sound: str, listen_during_wake_sound: bool = False -) -> VoiceSatelliteProtocol: +def _satellite(continue_conversation_sound: str, listen_during_wake_sound: bool = False) -> VoiceSatelliteProtocol: satellite = VoiceSatelliteProtocol.__new__(VoiceSatelliteProtocol) - satellite.state = SimpleNamespace( + satellite.state = SimpleNamespace( # type: ignore[assignment] continue_conversation_sound=continue_conversation_sound, continue_conversation_delay=0.0, listen_during_wake_sound=listen_during_wake_sound, @@ -20,8 +18,8 @@ def _satellite( active_wake_words=set(), stop_word=SimpleNamespace(id="stop"), ) - satellite.send_messages = MagicMock() - satellite._emit = MagicMock() + satellite.send_messages = MagicMock() # type: ignore[method-assign] + satellite._emit = MagicMock() # type: ignore[method-assign] satellite._continue_conversation = True satellite._is_streaming_audio = False satellite._pipeline_active = True From 808d6c7adaaf60965cbd2201c1d73bd3bc0f8582 Mon Sep 17 00:00:00 2001 From: ChrisB85 Date: Fri, 25 Sep 2026 14:00:32 +0200 Subject: [PATCH 3/7] Make the follow-up sound opt-in via a Home Assistant switch Traditional satellites such as the Voice PE stay silent on follow-up questions, so the sound is now off by default. A "Follow-up Sound" config switch (like "Thinking Sound") turns it on; its state is kept in preferences. --continue-conversation-sound still picks the file. --- .env.example | 4 +- README.md | 2 +- docker-entrypoint.sh | 3 +- docs/install_application.md | 2 +- linux_voice_assistant/__main__.py | 2 +- linux_voice_assistant/entity.py | 49 +++++++++++++++++++++++ linux_voice_assistant/models.py | 5 ++- linux_voice_assistant/satellite.py | 31 +++++++++++++- tests/test_continue_conversation_sound.py | 19 ++++++++- tests/unit/test_satellite.py | 22 ++++++++++ 10 files changed, 128 insertions(+), 11 deletions(-) diff --git a/.env.example b/.env.example index c39f337d..b116b2ee 100644 --- a/.env.example +++ b/.env.example @@ -108,8 +108,8 @@ LVA_PULSE_COOKIE="/run/user/${LVA_USER_ID}/pulse/cookie" # PROCESSING_SOUND="sounds/processing.wav" # MUTE_SOUND="sounds/mute_switch_on.flac" # UNMUTE_SOUND="sounds/mute_switch_off.flac" -# Sound played when the microphone re-opens for a follow-up question. -# Defaults to WAKEUP_SOUND. Set to "" to disable. +# Sound played when the microphone re-opens for a follow-up question +# (enable it with the "Follow-up Sound" switch in Home Assistant). Defaults to WAKEUP_SOUND. # CONTINUE_CONVERSATION_SOUND="sounds/wake_word_triggered.flac" ### Enable output-only mode (optional): diff --git a/README.md b/README.md index 62ff968f..11f4d96b 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ usage: __main__.py [-h] [--name NAME] [--audio-input-device AUDIO_INPUT_DEVICE] | `--processing-sound` | Sound played while assistant is processing | `sounds/processing.wav` | | `--mute-sound` | Sound played when muting the assistant | `sounds/mute_switch_on.flac` | | `--unmute-sound` | Sound played when unmuting the assistant | `sounds/mute_switch_off.flac` | -| `--continue-conversation-sound` | Sound played when the mic re-opens for a follow-up question | `--wakeup-sound` (`""` disables) | +| `--continue-conversation-sound` | Sound played when the mic re-opens for a follow-up question | `--wakeup-sound` | | `--preferences-file` | Path to preferences JSON file | `preferences.json` | | `--host` | IP-Address for ESPHome server, use 0.0.0.0 for all | Autodetected | | `--network-interface` | Network interface for ESPHome server | Autodetected | diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 2a31f869..28eea7ec 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -116,8 +116,7 @@ if [ -n "${UNMUTE_SOUND}" ]; then EXTRA_ARGS+=( "--unmute-sound" "$UNMUTE_SOUND" ) fi -# Set-but-empty is meaningful here: it disables the sound. -if [ -n "${CONTINUE_CONVERSATION_SOUND+x}" ]; then +if [ -n "${CONTINUE_CONVERSATION_SOUND}" ]; then EXTRA_ARGS+=( "--continue-conversation-sound" "$CONTINUE_CONVERSATION_SOUND" ) fi diff --git a/docs/install_application.md b/docs/install_application.md index f986fe04..a0637aa5 100644 --- a/docs/install_application.md +++ b/docs/install_application.md @@ -290,7 +290,7 @@ The following variables can be configured in the `.env` or in the service file: | `LISTEN_DURING_WAKE_SOUND` | false | Set to "1" to start listening immediately after wake word detection, without waiting for the wake sound to finish | | `MUTE_SOUND` | `sounds/mute_switch_on.flac` | Sound file for mute on | | `UNMUTE_SOUND` | `sounds/mute_switch_off.flac` | Sound file for mute off | -| `CONTINUE_CONVERSATION_SOUND` | same as `WAKEUP_SOUND` | Sound file played when the mic re-opens for a follow-up question (set to "" to disable) | +| `CONTINUE_CONVERSATION_SOUND` | same as `WAKEUP_SOUND` | Sound file played when the mic re-opens for a follow-up question (off by default, enable with the "Follow-up Sound" switch in Home Assistant) | | `PERIPHERAL_HOST` | 0.0.0.0 | Host for the peripheral WebSocket API | | `PERIPHERAL_PORT` | 6055 | Port for the peripheral WebSocket API | | `PERIPHERAL_VOLUME_STEP` | %(default)s | Volume change per button press | diff --git a/linux_voice_assistant/__main__.py b/linux_voice_assistant/__main__.py index ac4f71d2..01f3ed3a 100644 --- a/linux_voice_assistant/__main__.py +++ b/linux_voice_assistant/__main__.py @@ -150,7 +150,7 @@ async def main() -> None: ) parser.add_argument( "--continue-conversation-sound", - help="Sound to play when the microphone re-opens for a follow-up question (default: same as --wakeup-sound, empty string disables)", + help="Sound to play when the microphone re-opens for a follow-up question, if enabled from Home Assistant (default: same as --wakeup-sound)", ) parser.add_argument( "--button-double-press-sound", diff --git a/linux_voice_assistant/entity.py b/linux_voice_assistant/entity.py index 6636b333..05352f72 100644 --- a/linux_voice_assistant/entity.py +++ b/linux_voice_assistant/entity.py @@ -383,6 +383,54 @@ def handle_message(self, msg: message.Message) -> Iterable[message.Message]: yield SwitchStateResponse(key=self.key, state=self._switch_state) +class ContinueConversationSoundEntity(ESPHomeEntity): + """Switch entity for the sound played when the mic re-opens for a follow-up question.""" + + def __init__( + self, + server: APIServer, + key: int, + name: str, + object_id: str, + get_enabled: Callable[[], bool], + set_enabled: Callable[[bool], None], + ) -> None: + ESPHomeEntity.__init__(self, server) + self.key = key + self.name = name + self.object_id = object_id + self._get_enabled = get_enabled + self._set_enabled = set_enabled + self._switch_state = self._get_enabled() + + def update_get_enabled(self, get_enabled: Callable[[], bool]) -> None: + self._get_enabled = get_enabled + + def update_set_enabled(self, set_enabled: Callable[[bool], None]) -> None: + self._set_enabled = set_enabled + + def sync_with_state(self) -> None: + self._switch_state = self._get_enabled() + + def handle_message(self, msg: message.Message) -> Iterable[message.Message]: + if isinstance(msg, SwitchCommandRequest) and (msg.key == self.key): + new_state = bool(msg.state) + self._switch_state = new_state + self._set_enabled(new_state) + yield SwitchStateResponse(key=self.key, state=self._switch_state) + elif isinstance(msg, ListEntitiesRequest): + yield ListEntitiesSwitchResponse( + object_id=self.object_id, + key=self.key, + name=self.name, + entity_category=EntityCategory.CONFIG, + icon="mdi:bell-ring-outline", + ) + elif isinstance(msg, SubscribeHomeAssistantStatesRequest): + self.sync_with_state() + yield SwitchStateResponse(key=self.key, state=self._switch_state) + + class MicSettingEntity(ESPHomeEntity): def __init__( self, @@ -866,6 +914,7 @@ def handle_message(self, msg: message.Message) -> Iterable[message.Message]: "MediaPlayerEntity", "MuteSwitchEntity", "ThinkingSoundEntity", + "ContinueConversationSoundEntity", "LEDLightEntity", "ButtonEventSensorEntity", "ButtonLockEntity", diff --git a/linux_voice_assistant/models.py b/linux_voice_assistant/models.py index 082eefa3..46cf11cf 100644 --- a/linux_voice_assistant/models.py +++ b/linux_voice_assistant/models.py @@ -17,6 +17,7 @@ from .entity import ( ButtonEventSensorEntity, ButtonLockEntity, + ContinueConversationSoundEntity, ESPHomeEntity, LEDLightEntity, MediaPlayerEntity, @@ -86,6 +87,7 @@ class Preferences: active_wake_words: List[Optional[str]] = field(default_factory=list) volume: Optional[float] = None thinking_sound: int = 0 # 0 = disabled, 1 = enabled + continue_conversation_sound: int = 0 # 0 = disabled, 1 = enabled button_controls_locked: int = 0 # 0 = buttons enabled (default), 1 = buttons locked wake_word_1_sensitivity: Optional[float] = None wake_word_2_sensitivity: Optional[float] = None @@ -127,13 +129,13 @@ class ServerState: download_dir: Path continue_conversation_delay: float = 0.5 # seconds to wait after TTS before opening mic - # Empty string disables the sound. continue_conversation_sound: str = "" media_player_entity: "Optional[MediaPlayerEntity]" = None satellite: "Optional[VoiceSatelliteProtocol]" = None connections: "List[VoiceSatelliteProtocol]" = field(default_factory=list) mute_switch_entity: "Optional[MuteSwitchEntity]" = None thinking_sound_entity: "Optional[ThinkingSoundEntity]" = None + continue_conversation_sound_entity: "Optional[ContinueConversationSoundEntity]" = None button_event_sensor_entity: "Optional[ButtonEventSensorEntity]" = None # Lights declared by peripherals via register_light. Survives HA @@ -170,6 +172,7 @@ class ServerState: wake_words_changed: bool = False refractory_seconds: float = 2.0 thinking_sound_enabled: bool = False + continue_conversation_sound_enabled: bool = False button_controls_locked: bool = False output_only: bool = False muted: bool = False diff --git a/linux_voice_assistant/satellite.py b/linux_voice_assistant/satellite.py index 1e7240b3..92a1bdb8 100644 --- a/linux_voice_assistant/satellite.py +++ b/linux_voice_assistant/satellite.py @@ -53,6 +53,7 @@ from .entity import ( ButtonEventSensorEntity, ButtonLockEntity, + ContinueConversationSoundEntity, LEDLightEntity, MediaPlayerEntity, MicSettingEntity, @@ -181,6 +182,28 @@ def __init__(self, state: ServerState) -> None: thinking_sound_switch.update_set_thinking_sound_enabled(self._set_thinking_sound_enabled) thinking_sound_switch.sync_with_state() + # Add/update follow-up (continue conversation) sound entity + self.state.continue_conversation_sound_enabled = bool(self.state.preferences.continue_conversation_sound) + follow_up_sound_switch = self.state.continue_conversation_sound_entity + if follow_up_sound_switch is None: + follow_up_sound_switch = ContinueConversationSoundEntity( + server=self, + key=len(state.entities), + name="Follow-up Sound", + object_id="continue_conversation_sound", + get_enabled=lambda: self.state.continue_conversation_sound_enabled, + set_enabled=self._set_continue_conversation_sound_enabled, + ) + self.state.entities.append(follow_up_sound_switch) + self.state.continue_conversation_sound_entity = follow_up_sound_switch + elif follow_up_sound_switch not in self.state.entities: + self.state.entities.append(follow_up_sound_switch) + + follow_up_sound_switch.server = self + follow_up_sound_switch.update_get_enabled(lambda: self.state.continue_conversation_sound_enabled) + follow_up_sound_switch.update_set_enabled(self._set_continue_conversation_sound_enabled) + follow_up_sound_switch.sync_with_state() + # Add/update Wake Word 1 sensitivity number entity sensitivity_1_entity = self.state.sensitivity_1_number_entity if sensitivity_1_entity is None: @@ -488,6 +511,12 @@ def _on_button_lock_changed(self, is_locked: bool) -> None: # Mute / thinking sound # ------------------------------------------------------------------ + def _set_continue_conversation_sound_enabled(self, new_state: bool) -> None: + self.state.continue_conversation_sound_enabled = bool(new_state) + self.state.preferences.continue_conversation_sound = 1 if new_state else 0 + _LOGGER.debug("Follow-up sound %s", "enabled" if new_state else "disabled") + self.state.save_preferences() + def _set_thinking_sound_enabled(self, new_state: bool) -> None: self.state.thinking_sound_enabled = bool(new_state) self.state.preferences.thinking_sound = 1 if self.state.thinking_sound_enabled else 0 @@ -1013,7 +1042,7 @@ def _start_continued_conversation() -> None: self.unduck() return - if not self.state.continue_conversation_sound: + if not (self.state.continue_conversation_sound_enabled and self.state.continue_conversation_sound): _open_mic() elif self.state.listen_during_wake_sound: self.state.tts_player.play(self.state.continue_conversation_sound) diff --git a/tests/test_continue_conversation_sound.py b/tests/test_continue_conversation_sound.py index 9df36be0..4db16a92 100644 --- a/tests/test_continue_conversation_sound.py +++ b/tests/test_continue_conversation_sound.py @@ -10,6 +10,7 @@ def _satellite(continue_conversation_sound: str, listen_during_wake_sound: bool satellite = VoiceSatelliteProtocol.__new__(VoiceSatelliteProtocol) satellite.state = SimpleNamespace( # type: ignore[assignment] continue_conversation_sound=continue_conversation_sound, + continue_conversation_sound_enabled=True, continue_conversation_delay=0.0, listen_during_wake_sound=listen_during_wake_sound, muted=False, @@ -62,8 +63,9 @@ def test_listen_during_wake_sound_opens_mic_immediately(monkeypatch): assert satellite._is_streaming_audio -def test_empty_sound_disables_playback(monkeypatch): - satellite = _satellite("") +def test_switch_off_disables_playback(monkeypatch): + satellite = _satellite("wake.flac") + satellite.state.continue_conversation_sound_enabled = False timer_cls = MagicMock() monkeypatch.setattr("linux_voice_assistant.satellite.threading.Timer", timer_cls) @@ -98,3 +100,16 @@ def test_no_sound_when_conversation_ends(monkeypatch): timer_cls.assert_not_called() satellite.state.tts_player.play.assert_not_called() satellite.state.music_player.unduck.assert_called_once() + + +def test_switch_persists_to_preferences(): + satellite = _satellite("wake.flac") + satellite.state.continue_conversation_sound_enabled = False + satellite.state.preferences = SimpleNamespace(continue_conversation_sound=0) + satellite.state.save_preferences = MagicMock() + + satellite._set_continue_conversation_sound_enabled(True) + + assert satellite.state.continue_conversation_sound_enabled + assert satellite.state.preferences.continue_conversation_sound == 1 + satellite.state.save_preferences.assert_called_once() diff --git a/tests/unit/test_satellite.py b/tests/unit/test_satellite.py index a5824e4f..e50b2f8d 100644 --- a/tests/unit/test_satellite.py +++ b/tests/unit/test_satellite.py @@ -41,6 +41,13 @@ def test_thinking_sound_entity_created(self, tmp_path): assert sat.state.thinking_sound_entity is not None assert isinstance(sat.state.thinking_sound_entity, ThinkingSoundEntity) + def test_follow_up_sound_switch_created_disabled(self, tmp_path): + from linux_voice_assistant.entity import ContinueConversationSoundEntity + + sat = make_satellite(tmp_path) + assert isinstance(sat.state.continue_conversation_sound_entity, ContinueConversationSoundEntity) + assert sat.state.continue_conversation_sound_enabled is False + def test_mic_gain_entity_created(self, tmp_path): from linux_voice_assistant.entity import MicSettingEntity @@ -89,6 +96,21 @@ def test_thinking_sound_loaded_from_preferences(self, tmp_path): assert sat.state.thinking_sound_enabled is True + def test_follow_up_sound_loaded_from_preferences(self, tmp_path): + state = make_state(tmp_path) + state.preferences.continue_conversation_sound = 1 + + with ( + patch("linux_voice_assistant.satellite.WakeWord1SensitivityNumberEntity", MagicMock()), + patch("linux_voice_assistant.satellite.WakeWord2SensitivityNumberEntity", MagicMock()), + patch("linux_voice_assistant.satellite.StopWordSensitivityNumberEntity", MagicMock()), + ): + from linux_voice_assistant.satellite import VoiceSatelliteProtocol + + sat = VoiceSatelliteProtocol(state) + + assert sat.state.continue_conversation_sound_enabled is True + def test_output_only_sets_limited_features(self, tmp_path): from aioesphomeapi.model import VoiceAssistantFeature From 479171cefc3257be7fd7852b6a3dd503442e0174 Mon Sep 17 00:00:00 2001 From: Omar Amin <65174210+omaramin-2000@users.noreply.github.com> Date: Fri, 25 Sep 2026 16:18:24 +0300 Subject: [PATCH 4/7] Change icon from bell to chat question --- linux_voice_assistant/entity.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux_voice_assistant/entity.py b/linux_voice_assistant/entity.py index 05352f72..05bdfab1 100644 --- a/linux_voice_assistant/entity.py +++ b/linux_voice_assistant/entity.py @@ -424,7 +424,7 @@ def handle_message(self, msg: message.Message) -> Iterable[message.Message]: key=self.key, name=self.name, entity_category=EntityCategory.CONFIG, - icon="mdi:bell-ring-outline", + icon="mdi:chat-question", ) elif isinstance(msg, SubscribeHomeAssistantStatesRequest): self.sync_with_state() From c3ac110406723df36f69362f99590fe073deec41 Mon Sep 17 00:00:00 2001 From: Florian Asche Date: Wed, 2 Dec 2026 16:38:52 +0100 Subject: [PATCH 5/7] Let the follow-up sound option take 0 or 1 and give the sound file a default Co-Authored-By: Claude Sonnet 5.5 --- .env.example | 7 ++++--- docker-entrypoint.sh | 4 ++-- docs/behavior.md | 2 +- docs/configuration.md | 8 ++++---- linux_voice_assistant/__main__.py | 16 +++++++++------- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/.env.example b/.env.example index 0e54dbf5..c595891c 100644 --- a/.env.example +++ b/.env.example @@ -104,8 +104,9 @@ LVA_PULSE_COOKIE="/run/user/${LVA_USER_ID}/pulse/cookie" ### Enable thinking sound (optional): # ENABLE_THINKING_SOUND="1" -### Enable the sound for follow-up questions (optional): -# Plays CONTINUE_CONVERSATION_SOUND when the microphone opens again for the answer +### Sound for follow-up questions (optional): +# Plays CONTINUE_CONVERSATION_SOUND when the microphone opens again for the answer. +# "1" turns it on at every start, "0" off. Unset keeps the "Follow-up Sound" switch of Home Assistant (off at first) # ENABLE_CONTINUE_CONVERSATION_SOUND="1" ### Start listening during wake sound (optional): @@ -172,7 +173,7 @@ LVA_PULSE_COOKIE="/run/user/${LVA_USER_ID}/pulse/cookie" # BUTTON_TRIPLE_PRESS_SOUND="sounds/button_triple_press.flac" # BUTTON_LONG_PRESS_SOUND="sounds/button_long_press.flac" # Sound played when the microphone re-opens for a follow-up question -# (enable it with ENABLE_CONTINUE_CONVERSATION_SOUND or the "Follow-up Sound" switch in Home Assistant). Defaults to WAKEUP_SOUND. +# (enable it with ENABLE_CONTINUE_CONVERSATION_SOUND or the "Follow-up Sound" switch in Home Assistant). # CONTINUE_CONVERSATION_SOUND="sounds/wake_word_triggered.flac" ### Enable output-only mode (optional): diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index c2445c33..62b212ee 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -161,8 +161,8 @@ if [ "$ENABLE_THINKING_SOUND" = "1" ]; then EXTRA_ARGS+=( "--enable-thinking-sound" ) fi -if [ "$ENABLE_CONTINUE_CONVERSATION_SOUND" = "1" ]; then - EXTRA_ARGS+=( "--enable-continue-conversation-sound" ) +if [ -n "${ENABLE_CONTINUE_CONVERSATION_SOUND}" ]; then + EXTRA_ARGS+=( "--enable-continue-conversation-sound" "$ENABLE_CONTINUE_CONVERSATION_SOUND" ) fi if [ "$LISTEN_DURING_WAKE_SOUND" = "1" ]; then diff --git a/docs/behavior.md b/docs/behavior.md index efbbc244..e572422f 100644 --- a/docs/behavior.md +++ b/docs/behavior.md @@ -74,7 +74,7 @@ Details: - **Early speech.** If Home Assistant streams the reply (the response starts before it is complete), playback starts as soon as the first part is available. - **No spoken reply.** If the pipeline finishes without any speech (for example no speech was detected, an error, or a command with no reply), the pipeline ended sound (`--pipeline-ended-sound`) plays. Afterwards the assistant goes back to idle and music is restored. The sound is not played after announcements, when the reply is stopped with the stop word, when another satellite heard the same wake word and Home Assistant gave the run to it (`duplicate_wake_up_detected`), or when Home Assistant ends the run right after speech recognition because something else handles the transcript (for example the answer to a question asked by an automation). - **Continued conversation.** If Home Assistant asks a follow-up question, the assistant listens again after the reply, without a wake word. It waits `--continue-conversation-delay` (default 0.5 s) after the reply so the microphone does not record the tail of its own voice. Music stays ducked through the whole conversation and is restored only when the conversation ends. The follow-up runs on the same pipeline as the wake word that started the conversation. After a button press or an announcement from Home Assistant there is no wake word, so the first pipeline is used. If you mute the assistant during that delay, the follow-up is skipped and music is restored. -- **Follow-up sound.** With the *Follow-up Sound* switch on (off by default; `--enable-continue-conversation-sound` turns it on at every start), a sound tells you that the assistant listens again: `--continue-conversation-sound`, by default the wake sound. It plays after the delay above, also after an announcement that starts a conversation. Listening starts when the sound has finished, with `--listen-during-wake-sound` right away. Without `--listen-during-wake-sound`, stopping the sound (for example with a peripheral's stop command) or losing the connection to Home Assistant while it plays means that the assistant does not listen, and music is restored. A muted assistant plays no sound. +- **Follow-up sound.** With the *Follow-up Sound* switch on (off by default; `--enable-continue-conversation-sound 1` turns it on at every start, `0` off, without the option the switch keeps its stored setting), a sound tells you that the assistant listens again: `--continue-conversation-sound`, by default `sounds/wake_word_triggered.flac`, the file of the default wake sound (`--wakeup-sound` does not change it). It plays after the delay above, also after an announcement that starts a conversation. Listening starts when the sound has finished, with `--listen-during-wake-sound` right away. Without `--listen-during-wake-sound`, stopping the sound (for example with a peripheral's stop command) or losing the connection to Home Assistant while it plays means that the assistant does not listen, and music is restored. A muted assistant plays no sound. - **Wake word while a timer rings.** Saying the wake word silences the ringing timer and starts a normal interaction. - **Starting by button.** A peripheral button can start listening without a wake word. Instead of the wake sound, the start-listening sound (`--start-listening-sound`) plays; everything else is identical. This also silences a ringing timer. It does nothing while no wake word is active, see below. - **Errors.** If the pipeline reports an error, version 1 peripherals receive a `pipeline_error` event, version 2 peripherals the state `pipeline_error`. See [peripheral_api/readme.md](peripheral_api/readme.md). diff --git a/docs/configuration.md b/docs/configuration.md index 2220a014..87ec139b 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -10,7 +10,7 @@ ```sh usage: __main__.py [-h] [--name NAME] [--audio-input-device AUDIO_INPUT_DEVICE] [--list-input-devices] [--audio-input-block-size AUDIO_INPUT_BLOCK_SIZE] [--audio-output-device AUDIO_OUTPUT_DEVICE] [--music-output-device MUSIC_OUTPUT_DEVICE] [--mpv-player-duck-mode {duck,pause}] [--enable-sendspin-bridge {0,1}] [--sendspin-control-dir SENDSPIN_CONTROL_DIR] [--sendspin-player-duck-mode {pulse,stop,duck}] [--list-output-devices] [--wake-word-root-dir WAKE_WORD_ROOT_DIR] [--mic-auto-gain] [--mic-noise-suppression] [--wake-model WAKE_MODEL] [--wake-model-2 WAKE_MODEL_2] [--stop-model STOP_MODEL] [--refractory-seconds REFRACTORY_SECONDS] [--wakeup-sound WAKEUP_SOUND] [--timer-finished-sound TIMER_FINISHED_SOUND] [--processing-sound PROCESSING_SOUND] [--continue-conversation-sound CONTINUE_CONVERSATION_SOUND] - [--mute-sound MUTE_SOUND] [--unmute-sound UNMUTE_SOUND] [--preferences-file PREFERENCES_FILE] [--host HOST] [--network-interface NETWORK_INTERFACE] [--mac-address MAC_ADDRESS] [--port PORT] [--enable-encryption] [--encryption-key-file ENCRYPTION_KEY_FILE] [--enable-thinking-sound] [--enable-continue-conversation-sound] [--enable-zeroconf {0,1}] [--listen-during-wake-sound] [--debug] + [--mute-sound MUTE_SOUND] [--unmute-sound UNMUTE_SOUND] [--preferences-file PREFERENCES_FILE] [--host HOST] [--network-interface NETWORK_INTERFACE] [--mac-address MAC_ADDRESS] [--port PORT] [--enable-encryption] [--encryption-key-file ENCRYPTION_KEY_FILE] [--enable-thinking-sound] [--enable-continue-conversation-sound {0,1}] [--enable-zeroconf {0,1}] [--listen-during-wake-sound] [--debug] ``` @@ -66,7 +66,7 @@ usage: __main__.py [-h] [--name NAME] [--audio-input-device AUDIO_INPUT_DEVICE] | `--listen-during-wake-sound` | `LISTEN_DURING_WAKE_SOUND` | Start listening immediately after wake word detection, without waiting for the wake sound to finish | False | | `--continue-conversation-delay` | `CONTINUE_CONVERSATION_DELAY` | Delay before mic opens for continued conversation | 0.5 | | `--enable-thinking-sound` | `ENABLE_THINKING_SOUND` | Enable thinking sound on startup | False | -| `--enable-continue-conversation-sound` | `ENABLE_CONTINUE_CONVERSATION_SOUND` | Enable the sound for follow-up questions on startup (the *Follow-up Sound* switch) | False | +| `--enable-continue-conversation-sound` | `ENABLE_CONTINUE_CONVERSATION_SOUND` | `1` turns the sound for follow-up questions (the *Follow-up Sound* switch) on at startup, `0` off. Unset keeps the stored setting of the switch | unset (off at first) | | `--timer-max-ring-seconds` | `TIMER_MAX_RING_SECONDS` | Seconds after which the timer stops ringing | 900.0 | @@ -80,7 +80,7 @@ usage: __main__.py [-h] [--name NAME] [--audio-input-device AUDIO_INPUT_DEVICE] | `--start-listening-sound` | `START_LISTENING_SOUND` | Sound file played when button is pressed to start listening | `sounds/start_listening_button.flac` | | `--timer-finished-sound` | `TIMER_FINISHED_SOUND` | Sound file played when timer finishes | `sounds/timer_finished.flac` | | `--processing-sound` | `PROCESSING_SOUND` | Sound played while assistant is processing | `sounds/processing.wav` | -| `--continue-conversation-sound` | `CONTINUE_CONVERSATION_SOUND` | Sound file played when the microphone opens again for a follow-up question, if enabled | same as `--wakeup-sound` | +| `--continue-conversation-sound` | `CONTINUE_CONVERSATION_SOUND` | Sound file played when the microphone opens again for a follow-up question, if enabled | `sounds/wake_word_triggered.flac` | | `--mute-sound` | `MUTE_SOUND` | Sound played when muting the assistant | `sounds/mute_switch_on.flac` | | `--unmute-sound` | `UNMUTE_SOUND` | Sound played when unmuting the assistant | `sounds/mute_switch_off.flac` | | `--button-double-press-sound` | `BUTTON_DOUBLE_PRESS_SOUND` | Sound played on button double press | `sounds/button_double_press.flac` | @@ -202,7 +202,7 @@ The **Thinking Sound** switch turns on a short chime that plays while the assist Matching parameters: `--enable-continue-conversation-sound`, `--continue-conversation-sound`
Matching environment variables: `ENABLE_CONTINUE_CONVERSATION_SOUND`, `CONTINUE_CONVERSATION_SOUND` -The **Follow-up Sound** switch plays a sound when the assistant asks a follow-up question and the microphone opens again for your answer. It is off by default. The sound is the wake sound unless `--continue-conversation-sound` names another file. See [behavior.md](behavior.md#talking-to-the-assistant). +The **Follow-up Sound** switch plays a sound when the assistant asks a follow-up question and the microphone opens again for your answer. It is off by default. By default it is the same file as the default wake sound; `--continue-conversation-sound` names another one. `--wakeup-sound` does not change it. See [behavior.md](behavior.md#talking-to-the-assistant). diff --git a/linux_voice_assistant/__main__.py b/linux_voice_assistant/__main__.py index 81759b04..4f80b0a0 100644 --- a/linux_voice_assistant/__main__.py +++ b/linux_voice_assistant/__main__.py @@ -222,7 +222,8 @@ async def main() -> None: ) parser.add_argument( "--continue-conversation-sound", - help="Sound to play when the microphone re-opens for a follow-up question, if enabled with --enable-continue-conversation-sound or in Home Assistant (default: same as --wakeup-sound)", + default=str(_SOUNDS_DIR / "wake_word_triggered.flac"), + help="Sound to play when the microphone re-opens for a follow-up question, if enabled with --enable-continue-conversation-sound 1 or in Home Assistant", ) parser.add_argument( "--button-double-press-sound", @@ -281,8 +282,9 @@ async def main() -> None: ) parser.add_argument( "--enable-continue-conversation-sound", - action="store_true", - help="Enable the sound for follow-up questions on startup", + type=int, + choices=(0, 1), + help="Turn the sound for follow-up questions on (1) or off (0) at startup; without it the stored setting of the Follow-up Sound switch is kept (off at first)", ) # ------------------------------------------------------------------ # Peripheral API (LEDs, buttons, HAT boards) @@ -534,8 +536,8 @@ async def main() -> None: if args.enable_thinking_sound: preferences.thinking_sound = 1 - if args.enable_continue_conversation_sound: - preferences.continue_conversation_sound = 1 + if args.enable_continue_conversation_sound is not None: + preferences.continue_conversation_sound = args.enable_continue_conversation_sound if args.mic_auto_gain or args.mic_noise_suppression: try: @@ -617,7 +619,7 @@ async def main() -> None: button_double_press_sound=args.button_double_press_sound, button_triple_press_sound=args.button_triple_press_sound, button_long_press_sound=args.button_long_press_sound, - continue_conversation_sound=(args.wakeup_sound if args.continue_conversation_sound is None else args.continue_conversation_sound), + continue_conversation_sound=args.continue_conversation_sound, preferences=preferences, preferences_path=preferences_path, timers=TimerList.from_dicts(preferences.timers), @@ -647,7 +649,7 @@ async def main() -> None: state.preferences.save(state.preferences_path) state.wake_words_changed = True - if args.enable_thinking_sound or args.enable_continue_conversation_sound or args.mic_volume is not None or args.mic_auto_gain or args.mic_noise_suppression: + if args.enable_thinking_sound or args.enable_continue_conversation_sound is not None or args.mic_volume is not None or args.mic_auto_gain or args.mic_noise_suppression: state.preferences.save(state.preferences_path) initial_volume_percent = int(round(initial_volume * 100)) From d8cd2247b455573e22505bdbfc7934a174b672c3 Mon Sep 17 00:00:00 2001 From: Florian Asche Date: Wed, 2 Dec 2026 16:46:05 +0100 Subject: [PATCH 6/7] Rename the follow-up sound to continued conversation sound Co-Authored-By: Claude Sonnet 5.5 --- .env.example | 6 +-- docs/behavior.md | 4 +- docs/configuration.md | 8 +-- linux_voice_assistant/__main__.py | 2 +- linux_voice_assistant/satellite.py | 50 +++++++++---------- tests/e2e/test_home_assistant_interface.py | 2 +- tests/unit/test_satellite.py | 4 +- ...satellite_continued_conversation_sound.py} | 18 +++---- 8 files changed, 47 insertions(+), 47 deletions(-) rename tests/unit/{test_satellite_follow_up_sound.py => test_satellite_continued_conversation_sound.py} (82%) diff --git a/.env.example b/.env.example index c595891c..cc4a71f5 100644 --- a/.env.example +++ b/.env.example @@ -104,9 +104,9 @@ LVA_PULSE_COOKIE="/run/user/${LVA_USER_ID}/pulse/cookie" ### Enable thinking sound (optional): # ENABLE_THINKING_SOUND="1" -### Sound for follow-up questions (optional): +### Sound for continued conversations (optional): # Plays CONTINUE_CONVERSATION_SOUND when the microphone opens again for the answer. -# "1" turns it on at every start, "0" off. Unset keeps the "Follow-up Sound" switch of Home Assistant (off at first) +# "1" turns it on at every start, "0" off. Unset keeps the "Continued Conversation Sound" switch of Home Assistant (off at first) # ENABLE_CONTINUE_CONVERSATION_SOUND="1" ### Start listening during wake sound (optional): @@ -173,7 +173,7 @@ LVA_PULSE_COOKIE="/run/user/${LVA_USER_ID}/pulse/cookie" # BUTTON_TRIPLE_PRESS_SOUND="sounds/button_triple_press.flac" # BUTTON_LONG_PRESS_SOUND="sounds/button_long_press.flac" # Sound played when the microphone re-opens for a follow-up question -# (enable it with ENABLE_CONTINUE_CONVERSATION_SOUND or the "Follow-up Sound" switch in Home Assistant). +# (enable it with ENABLE_CONTINUE_CONVERSATION_SOUND or the "Continued Conversation Sound" switch in Home Assistant). # CONTINUE_CONVERSATION_SOUND="sounds/wake_word_triggered.flac" ### Enable output-only mode (optional): diff --git a/docs/behavior.md b/docs/behavior.md index e572422f..96219906 100644 --- a/docs/behavior.md +++ b/docs/behavior.md @@ -33,7 +33,7 @@ LVA has two independent audio players that share one volume setting: | Player | Used for | |--------|----------| | **Music player** | Media sent from Home Assistant (music, radio, `media_player.play_media` without `announce`) | -| **Assistant player** | Wake / mute / unmute chimes, the thinking sound, the follow-up sound, spoken replies (TTS), announcements, timer ringing, button sounds | +| **Assistant player** | Wake / mute / unmute chimes, the thinking sound, the continued conversation sound, spoken replies (TTS), announcements, timer ringing, button sounds | The music player can be sent to a different sound card with `--music-output-device`. By default both use `--audio-output-device`. `--audio-output-device` defaults to `pulse`, the default PulseAudio output (PulseAudio itself, or PipeWire through `pipewire-pulse`). With `pulse` alone LVA names no device, so the sound server decides where the sound goes and the output follows a change of the default output while LVA runs, for example when a USB sound card is unplugged (observed with PipeWire). A device name carries its mpv driver as a prefix (for example `pulse/...`) and that driver is used. @@ -74,7 +74,7 @@ Details: - **Early speech.** If Home Assistant streams the reply (the response starts before it is complete), playback starts as soon as the first part is available. - **No spoken reply.** If the pipeline finishes without any speech (for example no speech was detected, an error, or a command with no reply), the pipeline ended sound (`--pipeline-ended-sound`) plays. Afterwards the assistant goes back to idle and music is restored. The sound is not played after announcements, when the reply is stopped with the stop word, when another satellite heard the same wake word and Home Assistant gave the run to it (`duplicate_wake_up_detected`), or when Home Assistant ends the run right after speech recognition because something else handles the transcript (for example the answer to a question asked by an automation). - **Continued conversation.** If Home Assistant asks a follow-up question, the assistant listens again after the reply, without a wake word. It waits `--continue-conversation-delay` (default 0.5 s) after the reply so the microphone does not record the tail of its own voice. Music stays ducked through the whole conversation and is restored only when the conversation ends. The follow-up runs on the same pipeline as the wake word that started the conversation. After a button press or an announcement from Home Assistant there is no wake word, so the first pipeline is used. If you mute the assistant during that delay, the follow-up is skipped and music is restored. -- **Follow-up sound.** With the *Follow-up Sound* switch on (off by default; `--enable-continue-conversation-sound 1` turns it on at every start, `0` off, without the option the switch keeps its stored setting), a sound tells you that the assistant listens again: `--continue-conversation-sound`, by default `sounds/wake_word_triggered.flac`, the file of the default wake sound (`--wakeup-sound` does not change it). It plays after the delay above, also after an announcement that starts a conversation. Listening starts when the sound has finished, with `--listen-during-wake-sound` right away. Without `--listen-during-wake-sound`, stopping the sound (for example with a peripheral's stop command) or losing the connection to Home Assistant while it plays means that the assistant does not listen, and music is restored. A muted assistant plays no sound. +- **Continued conversation sound.** With the *Continued Conversation Sound* switch on (off by default; `--enable-continue-conversation-sound 1` turns it on at every start, `0` off, without the option the switch keeps its stored setting), a sound tells you that the assistant listens again: `--continue-conversation-sound`, by default `sounds/wake_word_triggered.flac`, the file of the default wake sound (`--wakeup-sound` does not change it). It plays after the delay above, also after an announcement that starts a conversation. Listening starts when the sound has finished, with `--listen-during-wake-sound` right away. Without `--listen-during-wake-sound`, stopping the sound (for example with a peripheral's stop command) or losing the connection to Home Assistant while it plays means that the assistant does not listen, and music is restored. A muted assistant plays no sound. - **Wake word while a timer rings.** Saying the wake word silences the ringing timer and starts a normal interaction. - **Starting by button.** A peripheral button can start listening without a wake word. Instead of the wake sound, the start-listening sound (`--start-listening-sound`) plays; everything else is identical. This also silences a ringing timer. It does nothing while no wake word is active, see below. - **Errors.** If the pipeline reports an error, version 1 peripherals receive a `pipeline_error` event, version 2 peripherals the state `pipeline_error`. See [peripheral_api/readme.md](peripheral_api/readme.md). diff --git a/docs/configuration.md b/docs/configuration.md index 87ec139b..fb06ff11 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -66,7 +66,7 @@ usage: __main__.py [-h] [--name NAME] [--audio-input-device AUDIO_INPUT_DEVICE] | `--listen-during-wake-sound` | `LISTEN_DURING_WAKE_SOUND` | Start listening immediately after wake word detection, without waiting for the wake sound to finish | False | | `--continue-conversation-delay` | `CONTINUE_CONVERSATION_DELAY` | Delay before mic opens for continued conversation | 0.5 | | `--enable-thinking-sound` | `ENABLE_THINKING_SOUND` | Enable thinking sound on startup | False | -| `--enable-continue-conversation-sound` | `ENABLE_CONTINUE_CONVERSATION_SOUND` | `1` turns the sound for follow-up questions (the *Follow-up Sound* switch) on at startup, `0` off. Unset keeps the stored setting of the switch | unset (off at first) | +| `--enable-continue-conversation-sound` | `ENABLE_CONTINUE_CONVERSATION_SOUND` | `1` turns the sound for continued conversations (the *Continued Conversation Sound* switch) on at startup, `0` off. Unset keeps the stored setting of the switch | unset (off at first) | | `--timer-max-ring-seconds` | `TIMER_MAX_RING_SECONDS` | Seconds after which the timer stops ringing | 900.0 | @@ -196,13 +196,13 @@ The **Thinking Sound** switch turns on a short chime that plays while the assist -
-Follow-up Sound – Switch: play a sound when the assistant listens again +
+Continued Conversation Sound – Switch: play a sound when the assistant listens again Matching parameters: `--enable-continue-conversation-sound`, `--continue-conversation-sound`
Matching environment variables: `ENABLE_CONTINUE_CONVERSATION_SOUND`, `CONTINUE_CONVERSATION_SOUND` -The **Follow-up Sound** switch plays a sound when the assistant asks a follow-up question and the microphone opens again for your answer. It is off by default. By default it is the same file as the default wake sound; `--continue-conversation-sound` names another one. `--wakeup-sound` does not change it. See [behavior.md](behavior.md#talking-to-the-assistant). +The **Continued Conversation Sound** switch plays a sound when the assistant asks a follow-up question and the microphone opens again for your answer. It is off by default. By default it is the same file as the default wake sound; `--continue-conversation-sound` names another one. `--wakeup-sound` does not change it. See [behavior.md](behavior.md#talking-to-the-assistant).
diff --git a/linux_voice_assistant/__main__.py b/linux_voice_assistant/__main__.py index 4f80b0a0..452efa13 100644 --- a/linux_voice_assistant/__main__.py +++ b/linux_voice_assistant/__main__.py @@ -284,7 +284,7 @@ async def main() -> None: "--enable-continue-conversation-sound", type=int, choices=(0, 1), - help="Turn the sound for follow-up questions on (1) or off (0) at startup; without it the stored setting of the Follow-up Sound switch is kept (off at first)", + help="Turn the sound for continued conversations on (1) or off (0) at startup; without it the stored setting of the Continued Conversation Sound switch is kept (off at first)", ) # ------------------------------------------------------------------ # Peripheral API (LEDs, buttons, HAT boards) diff --git a/linux_voice_assistant/satellite.py b/linux_voice_assistant/satellite.py index 6b982f1e..b98874d1 100644 --- a/linux_voice_assistant/satellite.py +++ b/linux_voice_assistant/satellite.py @@ -194,27 +194,27 @@ def __init__(self, state: ServerState) -> None: thinking_sound_switch.update_set_thinking_sound_enabled(self._set_thinking_sound_enabled) thinking_sound_switch.sync_with_state() - # Add/update follow-up (continue conversation) sound entity + # Add/update continued conversation sound entity self.state.continue_conversation_sound_enabled = bool(self.state.preferences.continue_conversation_sound) - follow_up_sound_switch = self.state.continue_conversation_sound_entity - if follow_up_sound_switch is None: - follow_up_sound_switch = ContinueConversationSoundEntity( + continued_conversation_sound_switch = self.state.continue_conversation_sound_entity + if continued_conversation_sound_switch is None: + continued_conversation_sound_switch = ContinueConversationSoundEntity( server=self, key=len(state.entities), - name="Follow-up Sound", + name="Continued Conversation Sound", object_id="continue_conversation_sound", get_enabled=lambda: self.state.continue_conversation_sound_enabled, set_enabled=self._set_continue_conversation_sound_enabled, ) - self.state.entities.append(follow_up_sound_switch) - self.state.continue_conversation_sound_entity = follow_up_sound_switch - elif follow_up_sound_switch not in self.state.entities: - self.state.entities.append(follow_up_sound_switch) + self.state.entities.append(continued_conversation_sound_switch) + self.state.continue_conversation_sound_entity = continued_conversation_sound_switch + elif continued_conversation_sound_switch not in self.state.entities: + self.state.entities.append(continued_conversation_sound_switch) - follow_up_sound_switch.server = self - follow_up_sound_switch.update_get_enabled(lambda: self.state.continue_conversation_sound_enabled) - follow_up_sound_switch.update_set_enabled(self._set_continue_conversation_sound_enabled) - follow_up_sound_switch.sync_with_state() + continued_conversation_sound_switch.server = self + continued_conversation_sound_switch.update_get_enabled(lambda: self.state.continue_conversation_sound_enabled) + continued_conversation_sound_switch.update_set_enabled(self._set_continue_conversation_sound_enabled) + continued_conversation_sound_switch.sync_with_state() # Add/update Wake Word 1 sensitivity number entity sensitivity_1_entity = self.state.sensitivity_1_number_entity @@ -548,13 +548,13 @@ def _on_button_lock_changed(self, is_locked: bool) -> None: self._emit(LVAEvent.BUTTON_LOCK_CHANGED, {"locked": is_locked}) # ------------------------------------------------------------------ - # Mute / thinking sound / follow-up sound + # Mute / thinking sound / continued conversation sound # ------------------------------------------------------------------ def _set_continue_conversation_sound_enabled(self, new_state: bool) -> None: self.state.continue_conversation_sound_enabled = bool(new_state) self.state.preferences.continue_conversation_sound = 1 if new_state else 0 - _LOGGER.debug("Follow-up sound %s", "enabled" if new_state else "disabled") + _LOGGER.debug("Continued conversation sound %s", "enabled" if new_state else "disabled") self.state.preferences.save(self.state.preferences_path) def _set_thinking_sound_enabled(self, new_state: bool) -> None: @@ -1030,15 +1030,15 @@ def _start_continued_conversation() -> None: return if not (self.state.continue_conversation_sound_enabled and self.state.continue_conversation_sound): - self._send_follow_up_request() + self._send_continued_conversation_request() elif self.state.listen_during_wake_sound: - _LOGGER.debug("Playing follow-up sound while listening (listen_during_wake_sound enabled)") + _LOGGER.debug("Playing continued conversation sound while listening (listen_during_wake_sound enabled)") self.state.tts_player.play(self.state.continue_conversation_sound) - self._send_follow_up_request() + self._send_continued_conversation_request() else: # The sound plays first, so the microphone does not stream it back to Home Assistant - _LOGGER.debug("Playing follow-up sound before listening") - self.state.tts_player.play(self.state.continue_conversation_sound, done_callback=self._on_follow_up_sound_finished) + _LOGGER.debug("Playing continued conversation sound before listening") + self.state.tts_player.play(self.state.continue_conversation_sound, done_callback=self._on_continued_conversation_sound_finished) threading.Timer(self.state.continue_conversation_delay, _start_continued_conversation).start() elif pipeline_ended and self.state.pipeline_ended_sound: @@ -1053,18 +1053,18 @@ def _start_continued_conversation() -> None: _LOGGER.debug("TTS response finished") - def _on_follow_up_sound_finished(self) -> None: - """Callback invoked when the follow-up sound finishes or is stopped; begin STT streaming unless the conversation was ended meanwhile.""" + def _on_continued_conversation_sound_finished(self) -> None: + """Callback invoked when the continued conversation sound finishes or is stopped; begin STT streaming unless the conversation was ended meanwhile.""" # tts_player.stop() also invokes this callback, after stop() or a disconnect has ended the conversation if not self._pipeline_active or self.state.muted: - _LOGGER.debug("Skipping continued conversation after the follow-up sound (pipeline active: %s, muted: %s)", self._pipeline_active, self.state.muted) + _LOGGER.debug("Skipping continued conversation after the continued conversation sound (pipeline active: %s, muted: %s)", self._pipeline_active, self.state.muted) self._pipeline_active = False self.unduck() self._emit(LVAEvent.IDLE) return - self._send_follow_up_request() + self._send_continued_conversation_request() - def _send_follow_up_request(self) -> None: + def _send_continued_conversation_request(self) -> None: """Ask Home Assistant to listen for the answer to a follow-up question.""" _LOGGER.debug("Sending VoiceAssistantRequest to Home Assistant with wake_word_phrase '%s' (continued conversation)", self._wake_word_phrase) self.send_messages([_pipeline_start_request(self._wake_word_phrase)]) diff --git a/tests/e2e/test_home_assistant_interface.py b/tests/e2e/test_home_assistant_interface.py index e0a0ccd4..89f68d43 100644 --- a/tests/e2e/test_home_assistant_interface.py +++ b/tests/e2e/test_home_assistant_interface.py @@ -14,7 +14,7 @@ "Media Player", "Mute", "Thinking Sound", - "Follow-up Sound", + "Continued Conversation Sound", "Wake Word 1 Sensitivity", "Wake Word 2 Sensitivity", "Stop Word Sensitivity", diff --git a/tests/unit/test_satellite.py b/tests/unit/test_satellite.py index 48847774..68f3fffd 100644 --- a/tests/unit/test_satellite.py +++ b/tests/unit/test_satellite.py @@ -53,7 +53,7 @@ def test_thinking_sound_entity_created(self, tmp_path): assert sat.state.thinking_sound_entity is not None assert isinstance(sat.state.thinking_sound_entity, ThinkingSoundEntity) - def test_follow_up_sound_switch_created_disabled(self, tmp_path): + def test_continued_conversation_sound_switch_created_disabled(self, tmp_path): from linux_voice_assistant.entity import ContinueConversationSoundEntity sat = make_satellite(tmp_path) @@ -108,7 +108,7 @@ def test_thinking_sound_loaded_from_preferences(self, tmp_path): assert sat.state.thinking_sound_enabled is True - def test_follow_up_sound_loaded_from_preferences(self, tmp_path): + def test_continued_conversation_sound_loaded_from_preferences(self, tmp_path): state = make_state(tmp_path) state.preferences.continue_conversation_sound = 1 diff --git a/tests/unit/test_satellite_follow_up_sound.py b/tests/unit/test_satellite_continued_conversation_sound.py similarity index 82% rename from tests/unit/test_satellite_follow_up_sound.py rename to tests/unit/test_satellite_continued_conversation_sound.py index 8151d57e..8a7374f5 100644 --- a/tests/unit/test_satellite_follow_up_sound.py +++ b/tests/unit/test_satellite_continued_conversation_sound.py @@ -7,7 +7,7 @@ from .conftest import make_satellite -SOUND = "/sounds/follow_up.flac" +SOUND = "/sounds/continued_conversation.flac" @pytest.fixture(name="timer") @@ -17,7 +17,7 @@ def timer_fixture(monkeypatch): return timer -def _follow_up(tmp_path, timer, enabled=True, **state_overrides): +def _continue_conversation(tmp_path, timer, enabled=True, **state_overrides): """Finish a reply that asked a follow-up question and let the settle delay pass.""" satellite = make_satellite(tmp_path, {"continue_conversation_sound": SOUND, **state_overrides}) satellite.state.continue_conversation_sound_enabled = enabled @@ -34,7 +34,7 @@ def _finish_sound(satellite): def test_listens_after_the_sound(tmp_path, timer): - satellite = _follow_up(tmp_path, timer) + satellite = _continue_conversation(tmp_path, timer) assert satellite.state.tts_player.play.call_args.args == (SOUND,) satellite.send_messages.assert_not_called() @@ -47,28 +47,28 @@ def test_listens_after_the_sound(tmp_path, timer): def test_listens_at_once_with_listen_during_wake_sound(tmp_path, timer): - satellite = _follow_up(tmp_path, timer, listen_during_wake_sound=True) + satellite = _continue_conversation(tmp_path, timer, listen_during_wake_sound=True) satellite.state.tts_player.play.assert_called_once_with(SOUND) assert satellite._is_streaming_audio def test_no_sound_when_disabled(tmp_path, timer): - satellite = _follow_up(tmp_path, timer, enabled=False) + satellite = _continue_conversation(tmp_path, timer, enabled=False) satellite.state.tts_player.play.assert_not_called() assert satellite._is_streaming_audio def test_no_sound_when_muted(tmp_path, timer): - satellite = _follow_up(tmp_path, timer, muted=True) + satellite = _continue_conversation(tmp_path, timer, muted=True) satellite.state.tts_player.play.assert_not_called() assert not satellite._is_streaming_audio def test_stop_during_the_sound_ends_the_conversation(tmp_path, timer, caplog): - satellite = _follow_up(tmp_path, timer) + satellite = _continue_conversation(tmp_path, timer) satellite.state.tts_player.stop.side_effect = lambda: _finish_sound(satellite) with caplog.at_level(logging.DEBUG): @@ -77,11 +77,11 @@ def test_stop_during_the_sound_ends_the_conversation(tmp_path, timer, caplog): satellite.send_messages.assert_not_called() assert not satellite._is_streaming_audio assert not satellite.pipeline_active - assert "Skipping continued conversation after the follow-up sound" in caplog.text + assert "Skipping continued conversation after the continued conversation sound" in caplog.text def test_disconnect_during_the_sound_does_not_listen(tmp_path, timer): - satellite = _follow_up(tmp_path, timer) + satellite = _continue_conversation(tmp_path, timer) satellite.state.tts_player.stop.side_effect = lambda: _finish_sound(satellite) satellite.connection_lost(None) From f0275a3e3c5c5b3d9570f3aaeebc7e79aebc5a70 Mon Sep 17 00:00:00 2001 From: Florian Asche Date: Wed, 2 Dec 2026 16:59:14 +0100 Subject: [PATCH 7/7] Configure the continued conversation sound only by option, without a switch in Home Assistant --enable-continue-conversation-sound takes 0 (default) or 1. Co-Authored-By: Claude Sonnet 5.5 --- .env.example | 4 +- docs/behavior.md | 4 +- docs/configuration.md | 12 +---- linux_voice_assistant/__main__.py | 11 ++--- linux_voice_assistant/entity.py | 49 ------------------- linux_voice_assistant/models.py | 3 -- linux_voice_assistant/satellite.py | 31 +----------- tests/e2e/test_home_assistant_interface.py | 1 - tests/unit/test_satellite.py | 22 --------- ..._satellite_continued_conversation_sound.py | 19 +------ 10 files changed, 12 insertions(+), 144 deletions(-) diff --git a/.env.example b/.env.example index cc4a71f5..f876ba0a 100644 --- a/.env.example +++ b/.env.example @@ -106,7 +106,7 @@ LVA_PULSE_COOKIE="/run/user/${LVA_USER_ID}/pulse/cookie" ### Sound for continued conversations (optional): # Plays CONTINUE_CONVERSATION_SOUND when the microphone opens again for the answer. -# "1" turns it on at every start, "0" off. Unset keeps the "Continued Conversation Sound" switch of Home Assistant (off at first) +# "1" plays the sound, "0" (default) does not # ENABLE_CONTINUE_CONVERSATION_SOUND="1" ### Start listening during wake sound (optional): @@ -173,7 +173,7 @@ LVA_PULSE_COOKIE="/run/user/${LVA_USER_ID}/pulse/cookie" # BUTTON_TRIPLE_PRESS_SOUND="sounds/button_triple_press.flac" # BUTTON_LONG_PRESS_SOUND="sounds/button_long_press.flac" # Sound played when the microphone re-opens for a follow-up question -# (enable it with ENABLE_CONTINUE_CONVERSATION_SOUND or the "Continued Conversation Sound" switch in Home Assistant). +# (enable it with ENABLE_CONTINUE_CONVERSATION_SOUND). # CONTINUE_CONVERSATION_SOUND="sounds/wake_word_triggered.flac" ### Enable output-only mode (optional): diff --git a/docs/behavior.md b/docs/behavior.md index 96219906..44d7365f 100644 --- a/docs/behavior.md +++ b/docs/behavior.md @@ -74,7 +74,7 @@ Details: - **Early speech.** If Home Assistant streams the reply (the response starts before it is complete), playback starts as soon as the first part is available. - **No spoken reply.** If the pipeline finishes without any speech (for example no speech was detected, an error, or a command with no reply), the pipeline ended sound (`--pipeline-ended-sound`) plays. Afterwards the assistant goes back to idle and music is restored. The sound is not played after announcements, when the reply is stopped with the stop word, when another satellite heard the same wake word and Home Assistant gave the run to it (`duplicate_wake_up_detected`), or when Home Assistant ends the run right after speech recognition because something else handles the transcript (for example the answer to a question asked by an automation). - **Continued conversation.** If Home Assistant asks a follow-up question, the assistant listens again after the reply, without a wake word. It waits `--continue-conversation-delay` (default 0.5 s) after the reply so the microphone does not record the tail of its own voice. Music stays ducked through the whole conversation and is restored only when the conversation ends. The follow-up runs on the same pipeline as the wake word that started the conversation. After a button press or an announcement from Home Assistant there is no wake word, so the first pipeline is used. If you mute the assistant during that delay, the follow-up is skipped and music is restored. -- **Continued conversation sound.** With the *Continued Conversation Sound* switch on (off by default; `--enable-continue-conversation-sound 1` turns it on at every start, `0` off, without the option the switch keeps its stored setting), a sound tells you that the assistant listens again: `--continue-conversation-sound`, by default `sounds/wake_word_triggered.flac`, the file of the default wake sound (`--wakeup-sound` does not change it). It plays after the delay above, also after an announcement that starts a conversation. Listening starts when the sound has finished, with `--listen-during-wake-sound` right away. Without `--listen-during-wake-sound`, stopping the sound (for example with a peripheral's stop command) or losing the connection to Home Assistant while it plays means that the assistant does not listen, and music is restored. A muted assistant plays no sound. +- **Continued conversation sound.** With `--enable-continue-conversation-sound 1` (default 0 = off; there is no switch for it in Home Assistant), a sound tells you that the assistant listens again: `--continue-conversation-sound`, by default `sounds/wake_word_triggered.flac`, the file of the default wake sound (`--wakeup-sound` does not change it). It plays after the delay above, also after an announcement that starts a conversation. Listening starts when the sound has finished, with `--listen-during-wake-sound` right away. Without `--listen-during-wake-sound`, stopping the sound (for example with a peripheral's stop command) or losing the connection to Home Assistant while it plays means that the assistant does not listen, and music is restored. A muted assistant plays no sound. - **Wake word while a timer rings.** Saying the wake word silences the ringing timer and starts a normal interaction. - **Starting by button.** A peripheral button can start listening without a wake word. Instead of the wake sound, the start-listening sound (`--start-listening-sound`) plays; everything else is identical. This also silences a ringing timer. It does nothing while no wake word is active, see below. - **Errors.** If the pipeline reports an error, version 1 peripherals receive a `pipeline_error` event, version 2 peripherals the state `pipeline_error`. See [peripheral_api/readme.md](peripheral_api/readme.md). @@ -307,7 +307,7 @@ Some hardware can also mute its microphone itself. That **hardware mute** is sep - There is **one shared volume** for music and for all assistant sounds (chimes, replies, timer). Changing it on the media player entity or with a peripheral's volume buttons changes both. - The volume is saved in `preferences.json` and restored after a restart. -- **First start.** If the preferences file does not exist yet, it is created right at startup with the defaults and an info message is logged, instead of on the first change. Startup may write the file again, for example when the default wake words are stored or when `--enable-thinking-sound`, `--enable-continue-conversation-sound`, `--mic-volume`, `--mic-auto-gain` or `--mic-noise-suppression` is set. +- **First start.** If the preferences file does not exist yet, it is created right at startup with the defaults and an info message is logged, instead of on the first change. Startup may write the file again, for example when the default wake words are stored or when `--enable-thinking-sound`, `--mic-volume`, `--mic-auto-gain` or `--mic-noise-suppression` is set. - **Media player mute** (the speaker icon on the media player card) sets the volume to 0 and remembers the previous value. Unmuting restores it. - **Ducking** is temporary and independent of the set volume: it always means 50 % of the current volume. - A separate **Mic Volume** controls the microphone level. It does not affect playback, see [configuration.md](configuration.md). It is saved in `preferences.json` and restored after a restart. Only an explicitly given `--mic-volume` (0 to 100) overrides the stored value on start. Without it, the stored value is used, or 100 if none is stored yet. diff --git a/docs/configuration.md b/docs/configuration.md index fb06ff11..e1b470d5 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -66,7 +66,7 @@ usage: __main__.py [-h] [--name NAME] [--audio-input-device AUDIO_INPUT_DEVICE] | `--listen-during-wake-sound` | `LISTEN_DURING_WAKE_SOUND` | Start listening immediately after wake word detection, without waiting for the wake sound to finish | False | | `--continue-conversation-delay` | `CONTINUE_CONVERSATION_DELAY` | Delay before mic opens for continued conversation | 0.5 | | `--enable-thinking-sound` | `ENABLE_THINKING_SOUND` | Enable thinking sound on startup | False | -| `--enable-continue-conversation-sound` | `ENABLE_CONTINUE_CONVERSATION_SOUND` | `1` turns the sound for continued conversations (the *Continued Conversation Sound* switch) on at startup, `0` off. Unset keeps the stored setting of the switch | unset (off at first) | +| `--enable-continue-conversation-sound` | `ENABLE_CONTINUE_CONVERSATION_SOUND` | `1` plays a sound when the microphone opens again for a follow-up question, `0` does not. See [behavior](behavior.md#talking-to-the-assistant) | 0 | | `--timer-max-ring-seconds` | `TIMER_MAX_RING_SECONDS` | Seconds after which the timer stops ringing | 900.0 |
@@ -196,16 +196,6 @@ The **Thinking Sound** switch turns on a short chime that plays while the assist -
-Continued Conversation Sound – Switch: play a sound when the assistant listens again - -Matching parameters: `--enable-continue-conversation-sound`, `--continue-conversation-sound`
-Matching environment variables: `ENABLE_CONTINUE_CONVERSATION_SOUND`, `CONTINUE_CONVERSATION_SOUND` - -The **Continued Conversation Sound** switch plays a sound when the assistant asks a follow-up question and the microphone opens again for your answer. It is off by default. By default it is the same file as the default wake sound; `--continue-conversation-sound` names another one. `--wakeup-sound` does not change it. See [behavior.md](behavior.md#talking-to-the-assistant). - -
-
Media Player – Media player: play media, control the volume of music and voice diff --git a/linux_voice_assistant/__main__.py b/linux_voice_assistant/__main__.py index 452efa13..2a1f3d9a 100644 --- a/linux_voice_assistant/__main__.py +++ b/linux_voice_assistant/__main__.py @@ -223,7 +223,7 @@ async def main() -> None: parser.add_argument( "--continue-conversation-sound", default=str(_SOUNDS_DIR / "wake_word_triggered.flac"), - help="Sound to play when the microphone re-opens for a follow-up question, if enabled with --enable-continue-conversation-sound 1 or in Home Assistant", + help="Sound to play when the microphone re-opens for a follow-up question, if enabled with --enable-continue-conversation-sound 1", ) parser.add_argument( "--button-double-press-sound", @@ -283,8 +283,9 @@ async def main() -> None: parser.add_argument( "--enable-continue-conversation-sound", type=int, + default=0, choices=(0, 1), - help="Turn the sound for continued conversations on (1) or off (0) at startup; without it the stored setting of the Continued Conversation Sound switch is kept (off at first)", + help="1 plays --continue-conversation-sound when the microphone re-opens for a follow-up question, 0 does not (default: %(default)s)", ) # ------------------------------------------------------------------ # Peripheral API (LEDs, buttons, HAT boards) @@ -536,9 +537,6 @@ async def main() -> None: if args.enable_thinking_sound: preferences.thinking_sound = 1 - if args.enable_continue_conversation_sound is not None: - preferences.continue_conversation_sound = args.enable_continue_conversation_sound - if args.mic_auto_gain or args.mic_noise_suppression: try: import webrtc_noise_gain # type: ignore[import-untyped] # noqa: F401 @@ -620,6 +618,7 @@ async def main() -> None: button_triple_press_sound=args.button_triple_press_sound, button_long_press_sound=args.button_long_press_sound, continue_conversation_sound=args.continue_conversation_sound, + continue_conversation_sound_enabled=args.enable_continue_conversation_sound == 1, preferences=preferences, preferences_path=preferences_path, timers=TimerList.from_dicts(preferences.timers), @@ -649,7 +648,7 @@ async def main() -> None: state.preferences.save(state.preferences_path) state.wake_words_changed = True - if args.enable_thinking_sound or args.enable_continue_conversation_sound is not None or args.mic_volume is not None or args.mic_auto_gain or args.mic_noise_suppression: + if args.enable_thinking_sound or args.mic_volume is not None or args.mic_auto_gain or args.mic_noise_suppression: state.preferences.save(state.preferences_path) initial_volume_percent = int(round(initial_volume * 100)) diff --git a/linux_voice_assistant/entity.py b/linux_voice_assistant/entity.py index 29b812d7..8ddab303 100644 --- a/linux_voice_assistant/entity.py +++ b/linux_voice_assistant/entity.py @@ -604,54 +604,6 @@ def handle_message(self, msg: message.Message) -> Iterable[message.Message]: yield SwitchStateResponse(key=self.key, state=self._switch_state) -class ContinueConversationSoundEntity(ESPHomeEntity): - """Switch entity for the sound played when the mic re-opens for a follow-up question.""" - - def __init__( - self, - server: APIServer, - key: int, - name: str, - object_id: str, - get_enabled: Callable[[], bool], - set_enabled: Callable[[bool], None], - ) -> None: - ESPHomeEntity.__init__(self, server) - self.key = key - self.name = name - self.object_id = object_id - self._get_enabled = get_enabled - self._set_enabled = set_enabled - self._switch_state = self._get_enabled() - - def update_get_enabled(self, get_enabled: Callable[[], bool]) -> None: - self._get_enabled = get_enabled - - def update_set_enabled(self, set_enabled: Callable[[bool], None]) -> None: - self._set_enabled = set_enabled - - def sync_with_state(self) -> None: - self._switch_state = self._get_enabled() - - def handle_message(self, msg: message.Message) -> Iterable[message.Message]: - if isinstance(msg, SwitchCommandRequest) and (msg.key == self.key): - new_state = bool(msg.state) - self._switch_state = new_state - self._set_enabled(new_state) - yield SwitchStateResponse(key=self.key, state=self._switch_state) - elif isinstance(msg, ListEntitiesRequest): - yield ListEntitiesSwitchResponse( - object_id=self.object_id, - key=self.key, - name=self.name, - entity_category=EntityCategory.CONFIG, - icon="mdi:chat-question", - ) - elif isinstance(msg, SubscribeHomeAssistantStatesRequest): - self.sync_with_state() - yield SwitchStateResponse(key=self.key, state=self._switch_state) - - class MicSettingEntity(ESPHomeEntity): def __init__( self, @@ -1135,7 +1087,6 @@ def handle_message(self, msg: message.Message) -> Iterable[message.Message]: "MediaPlayerEntity", "MuteSwitchEntity", "ThinkingSoundEntity", - "ContinueConversationSoundEntity", "LEDLightEntity", "ButtonEventSensorEntity", "ButtonLockEntity", diff --git a/linux_voice_assistant/models.py b/linux_voice_assistant/models.py index 6fa78303..7228ec7f 100644 --- a/linux_voice_assistant/models.py +++ b/linux_voice_assistant/models.py @@ -22,7 +22,6 @@ from .entity import ( ButtonEventSensorEntity, ButtonLockEntity, - ContinueConversationSoundEntity, ESPHomeEntity, LEDLightEntity, MediaPlayerEntity, @@ -118,7 +117,6 @@ class Preferences: active_wake_words: List[Union[WakeWordSelection, str, None]] = field(default_factory=list) # a plain string is a value of an older version, see migrations.py volume: Optional[float] = None thinking_sound: int = 0 # 0 = disabled, 1 = enabled - continue_conversation_sound: int = 0 # 0 = disabled, 1 = enabled button_controls_locked: int = 0 # 0 = buttons enabled (default), 1 = buttons locked muted: int = 0 # 0 = microphone active (default), 1 = muted wake_word_1_sensitivity: Optional[float] = None @@ -215,7 +213,6 @@ class ServerState: hardware_muted: Optional[bool] = None hardware_mute_type: Optional[str] = None # none, changeable or read_only thinking_sound_entity: "Optional[ThinkingSoundEntity]" = None - continue_conversation_sound_entity: "Optional[ContinueConversationSoundEntity]" = None button_event_sensor_entity: "Optional[ButtonEventSensorEntity]" = None # Lights declared by peripherals via register_light. Survives HA diff --git a/linux_voice_assistant/satellite.py b/linux_voice_assistant/satellite.py index b98874d1..fcabc005 100644 --- a/linux_voice_assistant/satellite.py +++ b/linux_voice_assistant/satellite.py @@ -53,7 +53,6 @@ SENDSPIN_URI_PREFIX, ButtonEventSensorEntity, ButtonLockEntity, - ContinueConversationSoundEntity, LEDLightEntity, MediaPlayerEntity, MicSettingEntity, @@ -194,28 +193,6 @@ def __init__(self, state: ServerState) -> None: thinking_sound_switch.update_set_thinking_sound_enabled(self._set_thinking_sound_enabled) thinking_sound_switch.sync_with_state() - # Add/update continued conversation sound entity - self.state.continue_conversation_sound_enabled = bool(self.state.preferences.continue_conversation_sound) - continued_conversation_sound_switch = self.state.continue_conversation_sound_entity - if continued_conversation_sound_switch is None: - continued_conversation_sound_switch = ContinueConversationSoundEntity( - server=self, - key=len(state.entities), - name="Continued Conversation Sound", - object_id="continue_conversation_sound", - get_enabled=lambda: self.state.continue_conversation_sound_enabled, - set_enabled=self._set_continue_conversation_sound_enabled, - ) - self.state.entities.append(continued_conversation_sound_switch) - self.state.continue_conversation_sound_entity = continued_conversation_sound_switch - elif continued_conversation_sound_switch not in self.state.entities: - self.state.entities.append(continued_conversation_sound_switch) - - continued_conversation_sound_switch.server = self - continued_conversation_sound_switch.update_get_enabled(lambda: self.state.continue_conversation_sound_enabled) - continued_conversation_sound_switch.update_set_enabled(self._set_continue_conversation_sound_enabled) - continued_conversation_sound_switch.sync_with_state() - # Add/update Wake Word 1 sensitivity number entity sensitivity_1_entity = self.state.sensitivity_1_number_entity if sensitivity_1_entity is None: @@ -548,15 +525,9 @@ def _on_button_lock_changed(self, is_locked: bool) -> None: self._emit(LVAEvent.BUTTON_LOCK_CHANGED, {"locked": is_locked}) # ------------------------------------------------------------------ - # Mute / thinking sound / continued conversation sound + # Mute / thinking sound # ------------------------------------------------------------------ - def _set_continue_conversation_sound_enabled(self, new_state: bool) -> None: - self.state.continue_conversation_sound_enabled = bool(new_state) - self.state.preferences.continue_conversation_sound = 1 if new_state else 0 - _LOGGER.debug("Continued conversation sound %s", "enabled" if new_state else "disabled") - self.state.preferences.save(self.state.preferences_path) - def _set_thinking_sound_enabled(self, new_state: bool) -> None: self.state.thinking_sound_enabled = bool(new_state) self.state.preferences.thinking_sound = 1 if self.state.thinking_sound_enabled else 0 diff --git a/tests/e2e/test_home_assistant_interface.py b/tests/e2e/test_home_assistant_interface.py index 89f68d43..e1966b13 100644 --- a/tests/e2e/test_home_assistant_interface.py +++ b/tests/e2e/test_home_assistant_interface.py @@ -14,7 +14,6 @@ "Media Player", "Mute", "Thinking Sound", - "Continued Conversation Sound", "Wake Word 1 Sensitivity", "Wake Word 2 Sensitivity", "Stop Word Sensitivity", diff --git a/tests/unit/test_satellite.py b/tests/unit/test_satellite.py index 68f3fffd..c44733fd 100644 --- a/tests/unit/test_satellite.py +++ b/tests/unit/test_satellite.py @@ -53,13 +53,6 @@ def test_thinking_sound_entity_created(self, tmp_path): assert sat.state.thinking_sound_entity is not None assert isinstance(sat.state.thinking_sound_entity, ThinkingSoundEntity) - def test_continued_conversation_sound_switch_created_disabled(self, tmp_path): - from linux_voice_assistant.entity import ContinueConversationSoundEntity - - sat = make_satellite(tmp_path) - assert isinstance(sat.state.continue_conversation_sound_entity, ContinueConversationSoundEntity) - assert sat.state.continue_conversation_sound_enabled is False - def test_mic_gain_entity_created(self, tmp_path): from linux_voice_assistant.entity import MicSettingEntity @@ -108,21 +101,6 @@ def test_thinking_sound_loaded_from_preferences(self, tmp_path): assert sat.state.thinking_sound_enabled is True - def test_continued_conversation_sound_loaded_from_preferences(self, tmp_path): - state = make_state(tmp_path) - state.preferences.continue_conversation_sound = 1 - - with ( - patch("linux_voice_assistant.satellite.WakeWord1SensitivityNumberEntity", MagicMock()), - patch("linux_voice_assistant.satellite.WakeWord2SensitivityNumberEntity", MagicMock()), - patch("linux_voice_assistant.satellite.StopWordSensitivityNumberEntity", MagicMock()), - ): - from linux_voice_assistant.satellite import VoiceSatelliteProtocol - - sat = VoiceSatelliteProtocol(state) - - assert sat.state.continue_conversation_sound_enabled is True - def test_output_only_sets_limited_features(self, tmp_path): from aioesphomeapi.model import VoiceAssistantFeature diff --git a/tests/unit/test_satellite_continued_conversation_sound.py b/tests/unit/test_satellite_continued_conversation_sound.py index 8a7374f5..8e221fa2 100644 --- a/tests/unit/test_satellite_continued_conversation_sound.py +++ b/tests/unit/test_satellite_continued_conversation_sound.py @@ -19,8 +19,7 @@ def timer_fixture(monkeypatch): def _continue_conversation(tmp_path, timer, enabled=True, **state_overrides): """Finish a reply that asked a follow-up question and let the settle delay pass.""" - satellite = make_satellite(tmp_path, {"continue_conversation_sound": SOUND, **state_overrides}) - satellite.state.continue_conversation_sound_enabled = enabled + satellite = make_satellite(tmp_path, {"continue_conversation_sound": SOUND, "continue_conversation_sound_enabled": enabled, **state_overrides}) satellite.send_messages = MagicMock() satellite._continue_conversation = True satellite._tts_finished() @@ -88,19 +87,3 @@ def test_disconnect_during_the_sound_does_not_listen(tmp_path, timer): satellite.send_messages.assert_not_called() assert not satellite._is_streaming_audio - - -def test_switch_is_off_by_default(tmp_path): - satellite = make_satellite(tmp_path) - - assert satellite.state.continue_conversation_sound_enabled is False - - -def test_switch_stores_the_setting(tmp_path): - satellite = make_satellite(tmp_path) - - satellite._set_continue_conversation_sound_enabled(True) - - assert satellite.state.continue_conversation_sound_enabled - assert satellite.state.preferences.continue_conversation_sound == 1 - assert satellite.state.preferences_path.exists()