Skip to content
This repository was archived by the owner on Oct 6, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions programs/handle/home_assistant/bin/converse.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
import logging
import sys
import time
from pathlib import Path
from urllib.request import Request, urlopen

Expand All @@ -19,6 +20,7 @@ def main():
)
parser.add_argument("token_file", help="Path to file with authorization token")
parser.add_argument("--language", help="Language code to use")
parser.add_argument("--conversation_id_timeout", type=int, default=30, help="Invalidate conversation_id and start a new conversation if this number of seconds has passed since the last interaction")
parser.add_argument(
"--debug", action="store_true", help="Print DEBUG messages to console"
)
Expand All @@ -32,6 +34,10 @@ def main():
if args.language:
data_dict["language"] = args.language

conversation_id_file = Path(_DIR.parent.as_posix()+"/share/conversation_id")
if conversation_id_file.is_file() and time.time() - conversation_id_file.stat().st_mtime < args.conversation_id_timeout:
data_dict["conversation_id"] = conversation_id_file.read_text()

data = json.dumps(data_dict, ensure_ascii=False).encode("utf-8")
request = Request(args.url, data=data, headers=headers)

Expand All @@ -44,6 +50,11 @@ def main():
.get("speech", "")
)
print(response_text)
conversation_id = response.get("conversation_id")

if conversation_id:
conversation_id_file.parent.mkdir(parents=True, exist_ok=True)
conversation_id_file.write_text(conversation_id)


if __name__ == "__main__":
Expand Down
3 changes: 2 additions & 1 deletion rhasspy3/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -389,12 +389,13 @@ programs:
# 2. Put long-lived access token in etc/token
home_assistant:
command: |
bin/converse.py --language "${language}" "${url}" "${token_file}"
bin/converse.py --language "${language}" --conversation_id_timeout "${conversation_id_timeout}" "${url}" "${token_file}"
adapter: |
handle_adapter_text.py
template_args:
url: "http://localhost:8123/api/conversation/process"
token_file: "${data_dir}/token"
conversation_id_timeout: 30
language: ""

# Intent only: answer English date/time requests
Expand Down