From 7062c0a1c82d63b3b1b1685c6f9c7ac15b64ff3a Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 1 Mar 2021 20:27:35 +0000 Subject: [PATCH] Speak image descriptions --- epicyon.py | 8 +++++++- inbox.py | 17 ++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/epicyon.py b/epicyon.py index 25ac354ed..cd5874f4e 100644 --- a/epicyon.py +++ b/epicyon.py @@ -1951,7 +1951,13 @@ if args.speaker: espeak.set_parameter(espeak.Parameter.Range, srange) espeak.synth(html.unescape(speakerJson['name'])) time.sleep(3) - espeak.synth(html.unescape(speakerJson['say'])) + if not speakerJson['imageDescription']: + sayStr = speakerJson['say'] + else: + sayStr = speakerJson['say'] + '. ' + \ + speakerJson['imageDescription'] + espeak.synth(html.unescape(sayStr)) + prevSay = speakerJson['say'] time.sleep(20) sys.exit() diff --git a/inbox.py b/inbox.py index 2a33b621f..1239f490f 100644 --- a/inbox.py +++ b/inbox.py @@ -2157,18 +2157,33 @@ def _updateSpeaker(baseDir: str, nickname: str, domain: str, content = urllib.parse.unquote_plus(postJsonObject['object']['content']) content = html.unescape(content) content = removeHtml(htmlReplaceQuoteMarks(content)) + + imageDescription = '' + if postJsonObject['object'].get('attachment'): + attachList = postJsonObject['object']['attachment'] + if isinstance(attachList, list): + for img in attachList: + if not isinstance(img, dict): + continue + if img.get('name'): + if isinstance(img['name'], str): + imageDescription += \ + img['name'] + '. ' + summary = '' if postJsonObject['object'].get('summary'): if isinstance(postJsonObject['object']['summary'], str): summary = \ urllib.parse.unquote_plus(postJsonObject['object']['summary']) summary = html.unescape(summary) + speakerName = \ getDisplayName(baseDir, postJsonObject['actor'], personCache) speakerJson = { "name": speakerName, "summary": summary, - "say": content + "say": content, + "imageDescription": imageDescription } saveJson(speakerJson, speakerFilename)